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

manjusha_
Kilo Sage

@Andrew_TND 

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

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;

}

@Satyapriya 

 

yes it should be a single equal,it's just a spell mistake

 

Thanks,

Manjusha

Satyapriya
Mega Sage

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

}