how to construct approval link url in client script

Bala13
Kilo Guru

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 = '';
}
}

 

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

I didn't get what exactly needs to be done with the client script?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hello Ankur,

Appoligize if i confused you.

By using this client script, i will redirect the approval link to the logged in user approval page 

This will be achived by using logic of, if the logged in user id matches with the approval list and the user having any record for the CRS.

I wanted to get the sys id from script include and i need to pass it to client script.

Kindly suggest me how can i get this via script inlcude?

 

Here i have hardcoded the sys id, so i want that sysid to be generated dynamically.

This client script i am writing it in Sysapproval table and onload

function onLoad() {
var id = 'ff690bf91be31014006215ff034bcb03';
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;
alert(appr);
if ((name != approvername) && (appr)) {
location.href ="https://abc.service-now.com/nav_to.do?uri=sysapproval_approver.do?sys_id="+id;

}
}

Hi,

So are you saying even if approver opens any approval record it should redirect them to the approval record where they are the approver?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur,

 

If they click on the Approval link from the notification email, then it should get redirected to the record where they are the approver