- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2023 03:43 AM
Hello, just need some scripting help.
I've created a custom table to store "personas" and each one has a department assigned.
What I'm trying to achieve is if the department on the u_personas table matches the department on the user profile it will update the record with matching persona in field u_persona.
(function executeRule(current, previous /*null when async*/ ) {
var persona = new GlideRecord("u_persona");
persona.addQuery("department", current.getDisplayValue("department"));
persona.query();
while (persona.next());
if (persona.department == current.getDisplayValue("department")) {
current.u_software == persona.sys_id;
}
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2023 05:20 AM
Sorted it in the end...
var persona = new GlideRecord("u_persona");
var department = current.getDisplayValue('department');
persona.addEncodedQuery("department", department);
persona.query();
if (persona.next()) {
current.u_software = persona.sys_id;
persona.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2023 04:14 AM
Thank you, tried both before and after but doesnt work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2023 04:19 AM
You want update u_software field of user profile if department matches?
if above is your requirement ,try my code
Share screenshot if it does not work
Thanks,
Manjusha Bangale
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2023 04:29 AM
Hi Andrew Robinso1,
Please confirm that u_software is a reference field or not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2023 05:07 AM
Hi, yes its referened to the u_persona table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2023 04:42 AM - edited ‎09-28-2023 04:43 AM
Hi @Andrew_TND
What is the type of department field in u_persona table.
Also please check if its backend value is department or u_department as its a custom table field.
If its a reference field then you need to update your query
persona.addQuery("department",current.getValue("department");
Also can you tell us on which table this script is running...??
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates