
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2022 06:57 AM
Referencing this question: https://community.servicenow.com/community?id=community_question&sys_id=67394325db5cdbc01dcaf3231f96...
I have created a UI action to interact with a RESTful server, and I am trying to allow it to use client/UI input to control a variable, numberOfLabels.
The REST integration is working perfectly, and will pass the right data if provided, however the solution in the above answer is not working when it comes to passing the client input to the server function. See below:
//Client-side 'onclick' function
function runClientCode(){
//Prompt user for number of labels
var numOfLabels = prompt("How many labels?", 1);
//Error checking
if(typeof(numOfLabels) == 'undefined' || numOfLabels == null) return false;
//Set the value in the form
g_form.setValue('numberOfLabels', numOfLabels.toString());
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'print_label_inc'); //MUST call the 'Action name' set in this UI Action
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if(typeof(window) == 'undefined') runServerCode();
function runServerCode(){
try{
//Creation first
var r;
//Determine where the labels should be printed based on assignment group
var assignGroup = current.assignment_group.getDisplayValue();
if(assignGroup == 'ITS - Desktop Support Tech Center') r = new sn_ws.RESTMessageV2('DSTC Label Printers', 'DSTC tickets');
else r = new sn_ws.RESTMessageV2('DSTC Label Printers', 'Resnet tickets');
//Set ticket number and user fields from ticket
r.setStringParameterNoEscape('ticketNumber', current.getValue('number'));
r.setStringParameterNoEscape('user', current.u_cf_user.getDisplayValue());
r.setStringParameterNoEscape('numberOfLabels', current.numberOfLabels);
//Execute and sto response
var response = r.execute();
//Determine response body
var responseBody = response.haveError() ? response.getErrorMessage() : JSON.parse(response.getBody()).message;
responseBody = JSON.parse(responseBody);
}
catch (ex) {
var message = ex.message;
}
}
I am setting the value in the form with:
g_form.setValue('numberOfLabels', numOfLabels.toString());
(The value must be ultimately be passed to the server as a string, ex: '1' instead of 1)
And attempting to retrieve it directly with
r.setStringParameterNoEscape('numberOfLabels', current.numberOfLabels);
However, when the request gets to the server, the numerOfLabels field is invariably 'undefined'. I am fairly new to SNow, so I am not sure if I need to pre-create this field (as it does not exist inside of the Incident table).
Thank you for any help in advance ^.^
Solved! Go to Solution.
- Labels:
-
User Interface (UI)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2022 07:16 AM
Are all of the values other than numberOfLabels defined when the request gets to the server?
I would say, for certain, that these lines:
g_form.setValue('numberOfLabels', numOfLabels.toString());
r.setStringParameterNoEscape('numberOfLabels', current.numberOfLabels);
Would essentially do nothing if there is not a field on the actual current record to target (and numberOfLabels would not be a valid name on incident, you'd end up with u_numberoflabels). I'm not certain about the rest of the code, but I'd say yes, you need to add a field to incident and change those lines to reference that field name, at a minimum.
I hope this helps!
If this was helpful, or correct, please be kind and mark the answer appropriately.
Michael Jones - Proud member of the GlideFast Consulting Team
Michael D. Jones
Proud member of the GlideFast Consulting Team!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2022 01:51 PM
Absolutely. You can create a UI Policy on the table with no conditions (will always process) with an action to hide the field. That way it would never be visible to user, but would still be present on the form for your script to reference, set, etc.
I hope this helps!
If this was helpful, or correct, please be kind and mark the answer appropriately.
Michael Jones - Proud member of the GlideFast Consulting Team
Michael D. Jones
Proud member of the GlideFast Consulting Team!