mubangud Absent Member.
Absent Member.
11076 views

List multiple selection items into text field (getFieldValue/setFieldValue)


I have three single relational fields (Manufacturer, Model, Equipment type) that I want to have listed in a single text field. Is there a simpler javascript I can use that will only display the selected items, from these fields, reasonably? So far this is all I have gotten. My problem is that the information is displaying but bunched up with no spaces in between the items. Also since the three fields are selection fields, the "(None)" displays as well but would like the script to ignore or replace the "(None)" with a blank.

Input javascript:

AddLoadCallback (Propdetails);

function Propdetails() {

var assettype = GetFieldValue("ASSET_TYPE");

var modelhw = GetFieldValue("MODEL_NUMBER_HW_2");

var manufacturer = GetFieldValue("PROP_MANUFACTURER");

var equiptmenttype = GetFieldValue("PROP_EQUIPMENT_TYPE");

var modelsw = GetFieldValue("MODEL_NUMBER_OTHER");

var equiptmenttype = GetFieldValue("PROP_EQUIPMENT_TYPE");

var isprodetailshw =manufacturer+modelhw+equiptmenttype;

var isprodetailssw =manufacturer+modelsw+equiptmenttype;

if (assettype == "Hardware")

{

SetFieldValue("HARDWARE_PROPERTY_NEW", isprodetailshw);

}

else if (assettype == "Software/Other")

{

SetFieldValue("PROPERTY_DETAILS_OTHER", isprodetailssw);

}

}

AddLoadCallback (Propdetails);

AddChangeCallback("MODEL_NUMBER_HW_2", Propdetails);

AddChangeCallback("MODEL_NUMBER_OTHER", Propdetails);

AddChangeCallback("PROP_MANUFACTURER", Propdetails);

AddChangeCallback("PROP_EQUIPMENT_TYPE", Propdetails);

Results:ManufacturerModelEquipment type
0 Likes
6 Replies
bamos Absent Member.
Absent Member.

Re: List multiple selection items into text field (getFieldValue/setFieldValue)


When you're creating your variable do something like this so there are spaces between them.

instead of:

var isprodetailshw =manufacturer+modelhw+equiptmenttype;

do this:

var isprodetailshw =manufacturer+" "+modelhw+" "+equiptmenttype;

for your (None) problem just test for that value and change it.

if(myvalue=="(None)")

{

myvalue = " ";

}

That's over simplified but you get the point.
0 Likes
Highlighted
mubangud Absent Member.
Absent Member.

Re: List multiple selection items into text field (getFieldValue/setFieldValue)


Brian where would I need to place the "(None)" parameter in the script below. I got the spacing issue resolved but have not been able to figure out how to ignore the None yet.

AddLoadCallback (Propdetails);

function Propdetails( ) {

var assettype = GetFieldValue("ASSET_TYPE");

var modelhw = GetFieldValue("MODEL_NUMBER_HW_2");

var manufacturer = GetFieldValue("PROP_MANUFACTURER");

var equiptmenttype = GetFieldValue("PROP_EQUIPMENT_TYPE");

var modelsw = GetFieldValue("MODEL_NUMBER_OTHER");

var equiptmenttype = GetFieldValue("PROP_EQUIPMENT_TYPE");

var isprodetailshw = manufacturer+modelhw+equiptmenttype;

var isprodetailshw =manufacturer+" "+modelhw+" "+equiptmenttype;

var isprodetailssw =manufacturer+" "+modelsw+" "+equiptmenttype;

if (assettype == "Hardware")

{

if(modelhw=="(None)")

{

modelhw = " ";

}

if(manufacturer=="(None)")

{

manufacturer = " ";

}

if(equiptmenttype=="(None)")

{

equiptmenttype = " ";

}

if(modelsw=="(None)")

{

modelsw = " ";

}

SetFieldValue( "HARDWARE_PROPERTY_NEW", isprodetailshw);

}

else if (assettype == "Software/Other")

{

SetFieldValue( "PROPERTY_DETAILS_OTHER", isprodetailssw);

}

}

AddLoadCallback (Propdetails);

AddChangeCallback("MODEL_NUMBER_HW_2" , Propdetails);

AddChangeCallback("MODEL_NUMBER_OTHER" , Propdetails);

AddChangeCallback("PROP_MANUFACTURER" , Propdetails);

AddChangeCallback("PROP_EQUIPMENT_TYPE" , Propdetails);
0 Likes
bamos Absent Member.
Absent Member.

Re: List multiple selection items into text field (getFieldValue/setFieldValue)


You're close but you need to put these lines near the end before you do your SetFieldValues. You need to check for (None) before you assign those to your other variables. You can delete one of the two first lines here, they are assigning the same variable so the second one will always win.

var isprodetailshw = manufacturer+modelhw+equiptmenttype;

var isprodetailshw =manufacturer+" "+modelhw+" "+equiptmenttype;

var isprodetailssw =manufacturer+" "+modelsw+" "+equiptmenttype;
0 Likes
mubangud Absent Member.
Absent Member.

Re: List multiple selection items into text field (getFieldValue/setFieldValue)


Got it working. Thank you so much for your help!

AddLoadCallback (Propdetails);

function Propdetails( ) {

var assettype = GetFieldValue("ASSET_TYPE");

var modelhw = GetFieldValue("MODEL_NUMBER_HW_2");

if(modelhw=="(None)"){modelhw = " ";}

var manufacturer = GetFieldValue("PROP_MANUFACTURER");

if(manufacturer=="(None)"){manufacturer = " ";}

var equiptmenttype = GetFieldValue("PROP_EQUIPMENT_TYPE");

if(equiptmenttype=="(None)") {equiptmenttype = " ";}

var modelsw = GetFieldValue("MODEL_NUMBER_OTHER");

if(modelsw=="(None)") { modelsw = " ";}

var isprodetailshw =manufacturer+" "+modelhw+" "+equiptmenttype;

var isprodetailssw =manufacturer+" "+modelsw+" "+equiptmenttype;

if (assettype == "Hardware")

{

SetFieldValue("HARDWARE_PROPERTY_NEW", isprodetailshw);

}

else if (assettype == "Software/Other")

{

SetFieldValue("PROPERTY_DETAILS_OTHER", isprodetailssw);

}

}

AddLoadCallback (Propdetails);

AddChangeCallback("MODEL_NUMBER_HW_2", Propdetails);

AddChangeCallback("MODEL_NUMBER_OTHER", Propdetails);

AddChangeCallback("PROP_MANUFACTURER", Propdetails);

AddChangeCallback("PROP_EQUIPMENT_TYPE", Propdetails);
0 Likes
hcho Absent Member.
Absent Member.

Re: List multiple selection items into text field (getFieldValue/setFieldValue)


Did you attach this JS to the form or have it as part of the Form Action?
0 Likes
PM Thompson Acclaimed Contributor.
Acclaimed Contributor.

Re: List multiple selection items into text field (getFieldValue/setFieldValue)


Hannah:I'm guessing it was a JavaScript Item/Entity in Composer that was "added" to a form. Note that there are at least 5 different ways to get JavaScript directly onto a Transition form without resorting to modifying templates. You can also save the JS as a file on the server then use the $JAVASCRIPT() tag to "include" it. SBM Form Actions and HTML JavaScript Widgets have the added benefit of allowing you to use dynamic values (like "{_LoginId}" or "{Submitter}").For me, being able to edit the JS in Notepad++ (with syntax coloring) and use the JSLint plugin makes it a lot easier to find dumb typos before deploying. Very handy if a deploy takes more than a few minutes.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.