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

Hi its running on the sys_user table.

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

}

Hello @Andrew_TND 

 

persona.addEncodedQuery("department" , department);

 Is worked ...??

 

its should be like this know...As you are using "addEncodedQuery"

 

persona.addEncodedQuery("department="  + department);

 OR

persona.addQuery("department",department);

 

 

Vishal Birajdar
ServiceNow Developer

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