how to construct approval link url in client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2020 02:51 AM
Hello,
Can any one tell me how to construct the approval page url in client script?
Actually we have an approval link under notification which is triggering via workflow and the approval link has been working through email script.
There is some drawback using the approval link via workflow beacuse only single email is triggering to the approvers and if any of the approver is clicking on that link, it is taking to the first person name only..it is not taking to my approval page and the approver name is displaying some other name instead of my name.
So, i thought when they click on that link........by using client script i will match the approver name and logged in user name whomever clicks on that, so if it matches then it should redirect to my approval page.
Kindly help me here how do i constuct an URL in client script to redirect to approval page.
Email script of Approval link in notification:
-------------------------------------------------
doApprovalLink();
function doApprovalLink(){
var docid = current.sys_id;
var id = '';
var approval = new GlideRecord('sysapproval_approver');
approval.addQuery('document_id','=',docid);
approval.addQuery('state','requested');
approval.query();
if(approval.next()){
id = approval.sys_id;
}
var myapprovals = '';
myapprovals +='<a href="https://abc.service-now.com/nav_to.do?uri=sysapproval_approver.do?sys_id='+id+'">Approval Link</a> to Approve the CRS Record';
template.print("<div>");
template.print(myapprovals);
template.print("<div>");
}
Client script:
----------------
function onLoad() {
var name = g_user.getFullName();
alert("name :" + name);
var approvername = g_form.getDisplayBox("approver").value;
alert(approvername);
var str = "Temp/Edit Change Request Services:";
var appr = str.indexOf("Temp/Edit")>-1;
if ((name != approvername) && (appr)) {
location.href = '';
}
}
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2020 06:15 AM
Hi Lalitha,
From your comments,
'If they click on the Approval link from the notification email, then it should get redirected to the record where they are the approver'
there isn't any need for client script additionally. Mail script URL should suffice.
Unsure if that is not the case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2020 06:30 AM
Hello Jaspal,
I am consutructing the Aprpoval link via email script only, but somehow if the approver clicks on the link is not taking to the Approver record, it is showing some other approver name in the approver field.
If possible kindly check my code and if anythings need to modify pls let me know
doApprovalLink();
function doApprovalLink(){
var docid = current.sys_id;
var id = '';
var approval = new GlideRecord('sysapproval_approver');
approval.addQuery('document_id','=',docid);
approval.addQuery('state','requested');
approval.query();
if(approval.next()){
id = approval.sys_id;
}
var myapprovals = '';
myapprovals +='<a href="https://abc.service-now.com/nav_to.do?uri=sysapproval_approver.do?sys_id='+id+'">Approval Link</a> to Approve the CRS Record';
template.print("<div>");
template.print(myapprovals);
template.print("<div>");
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2020 06:41 AM
Then the issue with the 'id' returned from GlideRecord.
Can you try below
myapprovals +='<a href="https://abc.service-now.com/sysapproval_approver.do?sys_id='+id+'">Approval Link</a> to Approve the CRS Record';
Also, what table is notification triggered from?