How to Remove Condition Data Type Field Value

subashds6515
Tera Contributor

Hi,

 

I created the condition data type filed in the User Persona table. This condition filed reference to the department table once in the department table any department is deleted . In the condition, I am getting the sys_id I need to remove the sys_id. If anyone knows about this kind of scenario, could you please help me?

 

subashds6515_0-1723640907488.png

 

4 REPLIES 4

Sandeep Rajput
Tera Patron
Tera Patron

@subashds6515 You can create a business rule on the department table which runs on delete. In the business rule script. You can query the User persona table and check which records contains the condition where the deleted department was used. You can update those conditions and remove the deleted departments from them.

 

Hope this helps,

Hi @Sandeep Rajput ,

I have created an "After Delete" business rule. This is my code.

 

(function executeRule(current, previous /*null when async*/ ) {
    var persona = new GliedeRecord("u_user_persona");
    persona.addQuery("u_department", current.name);
    persona.query();   
    if (persona.next()) {       
        persona.setValue("u_department", '');
    }
})(current, previous);
 
Am I missing anything in this code?

@subashds6515 Your department field on the User persona table is a condition field and not a reference field. You need to apply contains filter and not = filter in the query. Update your query as follows.

 

Also, you forgot to update the persona record after setting the value. Adde the line in script for you.

 

function executeRule(current, previous /*null when async*/ ) {
    var persona = new GliedeRecord("u_user_persona");
    persona.addQuery("u_department",'CONTAINS',current.name);
    persona.query();   
    if (persona.next()) {       
        persona.setValue("u_department", '');
        persona.update();
    }
})(current, previous);

 

Thanks for the reply  @Sandeep Rajput 

We tried but it's not removing the value sysid is there. 

When we updated it, it changed the value but when we deleted the record sys ID was not removed from the condition field. 

at the same time, we did configure a notification to send when condition field changes...it was also not triggering in both the cases i.e while update and delete.