- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2018 11:53 AM
I've created a Client script to autopopulate a form based on the original entry. All in, I'd like to autopopulate 4 fields for alm_consumables.
I can get two to work, since I've built a reference to another table from which they are retrieved from. The other two are pulled from choice fields. I can autopopulate the field but the data is retrieving the value instead of the Label.
Is there a way to autopopulate the Value?
Client Script
Current result: subclass and substate are not populating properly to populate the alm_consumables
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2018 08:34 AM
Jacob,
The syntax you posted for setValue function is correct, however the problem in this scenario is what to put in the third parameter (Display Value). consume.u_subclass is a choice field and it will only output the value, not the Label and getDisplayValue doesnt work in client scripts.
My suggestion is :
Either perform a GlideAjax and return the values you want from server side
OR
Convert the variable types to SELECT BOX with proper type specifications
Thank you
Aman
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2018 08:26 AM
Hmmmmm, then another alternative it to convert these 2 Catalog item variables to TYPE of SELECT BOX.
In type specifications, choose the Choice table as alm_consumables and Choice field is [your field]
Leave your script as it it, even though your client script retrieves the value instead of Label, the Choice Field will take care of displaying the values in the form of Label.
Converting a variable to Choice type may not be your requirement, but again, this is just an alternative.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2018 01:58 PM
Hi Steve,
You are close to inserting the displayValue of your fields, however you need to provide the g_form.setValue methods with some more parameters.
Take a look at the following image:
As you can see, you have only declared it with the fieldName and Value, but miss the displayValue.
So in your case, it would be something like - g_form.setValue('model', consume.model, consume.model); - and so on.
Best regards,
Jacob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2018 02:00 PM
and, ServiceNow has documented all their APIs/methods here: https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_GlideFormSetValue_String_String_String
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2018 08:34 AM
Jacob,
The syntax you posted for setValue function is correct, however the problem in this scenario is what to put in the third parameter (Display Value). consume.u_subclass is a choice field and it will only output the value, not the Label and getDisplayValue doesnt work in client scripts.
My suggestion is :
Either perform a GlideAjax and return the values you want from server side
OR
Convert the variable types to SELECT BOX with proper type specifications
Thank you
Aman
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2018 01:28 AM
Agree with Aman. Then you want to do it server side through a script include and parse the labels from there to your client script