workflow runscript to approve automatic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2016 01:02 PM
HI,
Currently in our system when a change request is created they also need to submit it for approval(UI Action),this will generate approvals(through workflow) for each member of CAB team and one of the user from CAB team will review and approve their approval request and the next approvals will be generated to the CI owners.
what we want to modify is if someone from CAB team submit for approval workflow triggers and generate approvals for each member of CAB team and what we want here is the approval request of the person who submitted should be automatically Approve his approval request. i am guessing this could be either possible through runscript in workflow activity or a business rule. anyhelp will be greatly appreciated.
thanks,
sry
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2016 01:18 PM
We run this Business Rule on the sysapproval_approver table. You can modify to meet you specific requirements.
//Check to see if user has previously approved
approveDuplicateApproval();
function approveDuplicateApproval(){
if (current.document_id || current.sysapproval){
var app = new GlideRecord('sysapproval_approver');
app.addQuery('sysapproval', current.sysapproval);
app.addQuery('sys_id','!=',current.sys_id);
app.addQuery('approver', current.approver);
app.addEncodedQuery('state=requested^ORstate=not requested^ORstate=approved');
app.orderBy('state');
app.query();
while(app.next()){
//If previous approval is found set this approval to 'approved'
if (app.state == 'approved'){
current.state = 'approved';
current.comments = "Approval marked by system as 'Approved' due to a previous approval on the same record by the same user.";
} else {
current.state = 'not_required';
current.comments = "Approval marked by system as 'No Longer Required' due to a previous approval on the same record by the same user.";
}
}
}
}
Please mark as Helpful or Correct Answer if this was useful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2016 01:38 PM
Hi Robert, thanks for the prompt reply. there is a UI action "Submit Approval" on change request. if a member from CAB team click on this ui action, immediately workflow kicks off and generate approval requests for each member of CAB team. what i want is as soon as a CAB member click on "Submit Approval" UI action, i want system to recognize the user session, generate approval request and system approves his own request as "Approved". i am not sure if i write a business rule on sysapproval_approver table will do this. could you please provide me a broad explanation of your thoughts.
thanks,
sry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2016 01:58 PM
You can try this business rule on insert of the approval record. Remember this is generic and will act on any approval so you might need to add a condition to restrict this "auto approve" to only the records you want it to apply too.
// run on insert
approveForSelf();
function approveForSelf(){
if ((current.document_id || current.sysapproval) && current.approver == gs.getUserID){
current.state = 'approved';
current.comments = "Approval marked by system as 'Approved'.";
}
}
You could run a similar script in the workflow itself. More like the first one I posted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2016 02:14 AM