Field type "Document ID" to be used in a business rule

sowmyarajaram
Tera Expert

Hello All,

Could anyone help me to query on field type "Documnet id"?. I'm currently using below

(function executeRule(current, previous /*null when async*/) {


var gr1 = new GlideRecord("policy");
gr1.addQuery('number', current.number);
gr1.query();
while(gr1.next()){
var gr = new GlideRecord("sysapproval_approver");
gr.addQuery('document_id', current.sys_id);
gr.query();
while(gr.next()){
if(gr.state == "approved"){
current.state = "published";
current.active = true;
current.update();
action.setRedirectURL(current);
}
}
}
})(current, previous);

 

Here i'm not able to get into second while loop, field "document_id" is of the type "Document ID".

 

Sowmya

12 REPLIES 12

palmen
Tera Guru

Do you have any approval for the record you have in current.sys_id?
You could try and exchange current.sys_id to an actual sys_id of something you know you have in the approval table just to make sure there are no other errors.

current.sys_id will be the sys_id of the record from where the business rule is triggered

Daniele Songini
Tera Guru

I tried to query the field document_id and everything works correctly.

I suggest you to verify that it enters the first while and then print in the log the value of current.sys_id.


Raju Koyagura
Tera Guru

Its not the issue with document_id field because I tried my end with the below code and it worked. Can you please verify the current.sys_id value related any approvals exist in sysapproval_approver table.

 

var gr = new GlideRecord("sysapproval_approver");
gr.addQuery('source_id', current.sys_id); //which has some approval records in approval table 
gr.query();
while(gr.next()){
gs.print("value: "+ gr.getDisplayValue('state'));
}

 

Yes, i see the approval record on my policy table available on approval table