- 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:01 AM
I am considering your business rule is triggering on insert/update of user profile
Use if instead of while statement and business rule of type before update
(function executeRule(current, previous /*null when async*/ ) {
var persona = new GlideRecord("u_persona");
persona.addQuery("department", current.getDisplayValue("department"));
persona.query();
if (persona.next());
current.u_software == persona.sys_id;//u_software should be a refernce to u_persona table
}
})(current, previous);
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful based on the Impact
Thanks,
Manjusha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2023 04:21 AM
Hi Manjusha,
As we are updating the record so we should use single equals to i.e
if(persona.next()){
current.u_software= persona.sys_id;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2023 04:24 AM - edited 09-28-2023 04:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2023 04:04 AM - edited 09-28-2023 04:10 AM
Hi Andrew ,
Try This one
var persona = new GlideRecord("u_persona");
persona.addQuery("department", current.getDisplayValue("department"));
persona.query();
if(persona.next()){
persona.sys_id = current.u_software;
persona.update();
}