How to set current logged in user as assigned_to when a new incident is created.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago
Hi Guys,
Im using openFrame to load my client application in the servicenow and my client app does the searching, screenpop and create different records like incident/interaction etc.
I have built a Script Include which is called via the Scripted Rest API(https://dev311298.service-now.com/api/912875/nvx_cti_integration/execute). The script Include has different methods and one of it is "createRecord" which creates a interaction in this case with other data like opened_for, short_description, state etc. While all these details are set properly, i also want to set the assigned_to feild automatically using the script include. Currently i tried with below.
interactionGR.assigned_to = gs.getUserID();
Now the above code is getting the sysid of the admin user thru which i created a scoped application , under which the script include and scripted rest api is created.
Even if i login thru different user(say skale in this case) then it sets as "Guest" but the logged in user is skale.
I have the flexibility to create a new api if needed or new client/UI Script which will basically give me the sys_id of the current logged in user. Once i receive that, i can pass that sysid in the script include request which is creating Interaction.
Can you guys please help me with any of the suggestions that you think can help me in this case?
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
Hi @SomnathK ,
Here’s how you can ensure that the assigned_to field is set to the actual user who triggered the request, not the system user...
Ensure your client application / portal passes credentials/tokens that identify the user (e.g OAuth, JWT, session cookie). If the REST call uses a system or integration account, gs.getUserID() will return that account (often the admin or system) instead of the end user.....
and second will be,
From your front-end (OpenFrame / UI), call a Get Current User API (for example /api/now/table/sys_user/me) to retrieve the sys_id of the logged in user. Then include this sys_id in your Scripted REST API request (e.g. JSON body assigned_to: "<user_sys_id>").....Modify your Scripted REST API / Script Include to use the passed assigned_to...
If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/