- 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 08:28 AM
Hi,
Is this for another fresh request being raised not from the UI action?
if yes then I believe that's because the variable data is still present in the session
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 08:28 AM
Hi - Yes, that's correct Ankur.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2020 08:32 AM
You can try to use clearClientData()
So, after you set the values on form load, add lines like this to your script:
g_user.clearClientData('related_incident');
g_user.clearClientData('requested_for');
g_user.clearClientData('manager');
g_user.clearClientData('employee_location');
g_user.clearClientData('reason_computer_needed');
g_user.clearClientData('desk_number');
g_user.clearClientData('additional_details');
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 09:37 AM
That didn't work...all the variable values are cleared and no longer auto-populating. I also tested an onSubmit script and still no luck.
Is there a way to accomplish this without using Catalog Client Scripts and just in the UI Action script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2020 10:41 AM
So are you saying once values are set using session data and if you clear the session data the values are gone.
I don't think it should happen as values are already populated.
please try to clear the session values in onsubmit
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader