Business rule help - gliderecord

Andrew_TND
Mega Sage
Mega Sage

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);
1 ACCEPTED SOLUTION

Andrew_TND
Mega Sage
Mega Sage

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();

}

View solution in original post

12 REPLIES 12

Thank you, tried both before and after but doesnt work.

@Andrew_TND 

 

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

 

Satyapriya
Mega Sage

Hi Andrew Robinso1,

Please confirm that u_software is a reference field or not.

Hi, yes its referened to the u_persona table.

Vishal Birajdar
Giga Sage

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...??

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates