- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2020 07:19 AM
Hello Community,
I'm working on a project that includes the following requirements:
- Create Service Catalog Item to request for a PC Refresh.
- Use the 'Create Request' UI Action functionality to create this request from an Incident.
- When clicking on Create Request, the UI Action should do the following:
- In the incident, add note to Additional Comments stating that the incident was converted to a request.
- Redirect to the Catalog Item and auto-populate the variables on the request.
The fields are auto-populate and redirects to the Catalog Item as required, however the fields continue to stay populated instead of clearing the values once the Catalog Item request is submitted. Any assistance with my scripting would be much appreciated.
Catalog Client Script:
function onLoad() {
var inc = g_user.getClientData('related_incident');
g_form.setValue('related_incident', inc);
var req = g_user.getClientData('requested_for');
g_form.setValue('requested_for', req);
var mgr = g_user.getClientData('manager');
g_form.setValue('manager', mgr);
var loc = g_user.getClientData('employee_location');
g_form.setValue('employee_location', loc);
var com = g_user.getClientData('reason_computer_needed');
g_form.setValue('reason_computer_needed', com);
var dsk = g_user.getClientData('desk_number');
g_form.setValue('desk_number', dsk);
var add = g_user.getClientData('additional_details');
g_form.setValue('additional_details', add);
}
UI Action:
var ses = gs.getSession();
ses.putClientData('related_incident', current.number);
ses.putClientData('requested_for', current.caller_id.sys_id.toString());
ses.putClientData('manager', current.caller_id.manager.sys_id.toString());
ses.putClientData('employee_location', current.location);
ses.putClientData('desk_number', current.caller_id.u_desk_area);
ses.putClientData('reason_computer_needed', 'PC Refresh/Upgrade');
ses.putClientData('additional_details', 'Converted to Computer Request from Incident Number: ' + current.number + '\n\n' + 'Incident Description: ' + '\n' + current.description);
current.comments = 'Incident converted to request for fulfillment. '; //Script doesn't populate Additional Comments in Incident
gs.setRedirect('com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=51e2db16dbba1810a4c02d89139619d5');
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2020 05:07 PM
Hi Keimo
You can include below lines before gs.setRedirect in UI action
current.incident_state = '6';
current.close_code = 'Solved (Permanently)';
current.close_notes = 'Incident converted to request for fulfillment';
current.update();
I hope this answers your question.
- Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2020 09:45 PM
Nice to hear.
The answer you marked correct doesn't match to your question of the variables being populated/cleared.
It looks like answer to a secondary question on same post.
Please mark appropriate response as correct so that it would help future readers and won't confuse them.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2020 10:18 PM
Hi Ankur Bawiskar,
I think the main goal here is to help community users and let them decide which answer helped them. I would appreciate if you please don't post the similar message in other threads. I have seen your similar comment like this for other users lately in different thread as well hence my comment here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2020 10:25 PM
Hi Pradeep,
I agree the main goal is to help members.
I believe it won't help anyone to ask a secondary question on the same community post as it leads to confusion to future readers if they are looking for answer some months/years from now.
I believe it's better to create a second post so there's a separation in the questions being asked and other members can provide their thought as well.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2020 10:29 PM
Thanks for the update. The question is still around the same topic related to UI action so I believe it is not completely diverted from the original question for example the question is not deviated to other topic like Service Portal, catalog item,etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2020 10:44 PM
Please find below solution to your original question of variables issue and you won't require GlideAjax and Script Include
1) you can send the field value via URL in parameters as you are already taking users to specific catalog item
2) then use onLoad catalog client script to get parameters from url and set the value
UI Action code:
var url = 'com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=51e2db16dbba1810a4c02d89139619d5&sysparm_related_incident=' + current.number + '&sysparm_requested_for=' + current.caller_id.sys_id + '&sysparm_manager=' + current.caller_id.manager + '&sysparm_employee_location=' + current.location + '&sysparm_desk_number=' + current.caller_id.u_desk_area + '&sysparm_reason_computer_needed=' + 'PC Refresh/Upgrade' + '&sysparm_additional_details=' + 'Converted to Computer Request from Incident Number: ' + current.number + '\n\n' + 'Incident Description: ' + '\n' + current.description;
current.comments = 'Incident converted to request for fulfillment. '; //Script doesn't populate Additional Comments in Incident
gs.setRedirect(url);
Catalog Client Script: onLoad
function onLoad() {
var url = top.location.href;
var inc = new URLSearchParams(url).get("sysparm_related_incident");
g_form.setValue('related_incident', inc);
var req = new URLSearchParams(url).get("sysparm_requested_for");
g_form.setValue('requested_for', req);
var mgr = new URLSearchParams(url).get("sysparm_manager");
g_form.setValue('manager', mgr);
var loc = new URLSearchParams(url).get("sysparm_employee_location");
g_form.setValue('employee_location', loc);
var com = new URLSearchParams(url).get("sysparm_reason_computer_needed");
g_form.setValue('reason_computer_needed', com);
var dsk = new URLSearchParams(url).get("sysparm_desk_number");
g_form.setValue('desk_number', dsk);
var add = new URLSearchParams(url).get("sysparm_additional_details");
g_form.setValue('additional_details', add);
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader