Field type "Document ID" to be used in a business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2018 03:42 AM
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
- Labels:
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2018 04:44 AM
Did you compare the sys_id of your policy table record and approval records document id? I suspect instead of passing the document_id of approval record, passing something different.
I am bit confused, why are you using GlideRecord for policy table? since you are no where using the gr1 so better remove that (unnecessary looping through the first while)
Try this way:
var gr = new GlideRecord("sysapproval_approver");
gr.addQuery('document_id', current.sys_id);
gr.query();
while(gr.next()){
//before updating the record, first print and see the records
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2018 05:32 AM
I have made some progress here.
i'm able to get into second while too, but however if condition is failing. the state is not "approved". i checked using logs.
However i'm not getting one thing here.. on an policy even when the record is approved, it still displays as requested on the debug logs, though the record is updated. any idea that how i can update this?
Sowmya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2018 05:40 AM
What value do you get with gr.state?
Is it "requested" or something else?
Is this a before business rule? If so the previous value will be displayed, might be that you need to make it an after business rule to get the new value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2018 06:06 AM
The state is said to be “Requested”. Additionally I’m trying with after business rule only.
Sowmya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2018 06:11 AM
What table is the business rule running on and what are the trigger conditions?