How to Identify SOW vs Native UI in Client Script and Set Incident Source Field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
Hi Experts,
I have a requirement to automatically populate the Source field on the Incident form based on where the Incident is opened from.
Requirement
If the user opens the Incident from Service Operations Workspace (SOW), set the Source field to "int_sow".
If the user opens the Incident from the Native UI, set the Source field to "inc_native_ui".
What I Tried
I tried to get the URL in a onload client script using:
var pathURL = top.location.href;
console.log(pathURL);
and
var pathURL = window.location.href;
console.log(pathURL);
Then I used logic like:
if (pathURL.indexOf('sow') > -1) {
g_form.setValue('source', 'int_sow');
} else {
g_form.setValue('source', 'inc_native_ui');
}
Issue
When an Incident is opened in SOW, both top.location.href and window.location.href return the Incident record URL instead of the SOW home page URL.
For example:
Expected URL
https://instance.service-now.com/now/sow/home
Actual URL Returned
https://instance.service-now.com/now/workspace/agent/record/incident/<sys_id>
or
https://instance.service-now.com/incident.do?sys_id=<sys_id>
Because of this, my condition to check for "sow" is not working.
Question
Is there a supported way in a Client Script to determine whether the Incident form was opened from:
Service Operations Workspace (SOW)
Native UI
If checking the URL is not recommended, what is the best practice to identify the interface and set the Source field accordingly?
Any examples or recommendations would be appreciated.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tuesday
Hi @ntest777 ,
Instead of checking for "sow" in the URL, try searching for the keyword "record" in the URL path.
The "record" path is specific to the Service Operations Workspace. So, if the URL contains "record", set the Source field to int_sow; otherwise, set it to inc_native_ui.
if (pathURL.indexOf('record') > -1) {
g_form.setValue('source', 'int_sow');
} else {
g_form.setValue('source', 'inc_native_ui');
} If my response helped, mark it as helpful and accept the solution.
Thanks,
Dinesh