Help to get Assessment sysid from server to pass it to client in Action type ESC to-dos page

Nani5
Tera Expert

Hello All,

 

I am working on one button (close with Survey) in ESC to-dos page. I am getting Assessment sysid in the server script and I want to use it(pass it) in the client side URL. This is being used in the Action type. Could you please assist.Below is the code I have used.

Note:If i pass the exact url of survey the page is redirecting and after submitting the survey,the ticket is getting closed.i want to do it in a dynamic way by passing assessment sysid.I tried using $scope and data aswell.

Server side:

var infoMessage = gs.getMessage("You have {0} this ticket.", "closed");
var errorMessage = gs.getMessage("Ticket could not be {0} try again.", State);
var closeSurveyURL='';
var gr = new GlideRecord('incident');
gr.addQuery('sys_id', sys_id);
gr.query();
if (gr.next()) {
    gr.incident_state = State;
    if (gr.update() == null) {
        gs.addErrorMessage(errorMessage);
    } else {
        gs.addInfoMessage(infoMessage);
    }
    var assesRecS = new GlideRecord('asmt_assessment_instance');
            assesRecS.addEncodedQuery('stateINready,wip^trigger_id=' + gr.sys_id.toString());
            assesRecS.orderByDesc("sys_created_on")  ;
            assesRecS.query();
            if (assesRecS.next()) {
                //data.incCloseSurvey = true;
                closeSurveyURL = "./assessment_take2.do?sysparm_assessable_type=" +assesRecS.metric_type+ "&sysparm_assessable_sysid="+assesRecS.sys_id;                
            }
}
Client side:
var comment = "";
var title = "${Reopen ticket}";
var message = "${Provide a reason for reopening this ticket}";
var primaryButtonLabel = "${Reopen}";
 
//var surveyURL ="./assessment_take2.do?sysparm_assessable_type=" +assesRecS.metric_type+ "&sysparm_assessable_sysid="+assesRecS.sys_id;
//var surveyURL ="/incident.do?sys_id=f1db20ca3bb8ae90f2162f37f4e45a50";
//"./assessment_take2.do?sysparm_assessable_type=" +assesRecS.metric_type+ "&sysparm_assessable_sysid="+assesRecS.sys_id;
//"./assessment_take2.do?sysparm_assessable_type=8836b8f61b1438103c6321f5604bcbb1&sysparm_assessable_sysid=d86c6a363bc92e540b70859aa4e45a74";
//var surveyURL =$scope.data.closeSurveyURL;
  // Open the survey in a new window
  var surveyURL ="./assessment_take2.do?sysparm_assessable_type=8836b8f61b1438103c6321f5604bcbb1&sysparm_assessable_sysid=d86c6a363bc92e540b70859aa4e45a74";
var answer=  window.open(surveyURL, "_blank");
answer.then(function(confirm) {
    if (!confirm.cancel) {
        if (isEsignatureEnabled == "false") {
           
            $rootScope.$broadcast(broadcastEventName, null);
            var payload = {};
            payload.name = "SC_APPROVER_ACTION";
            payload.data = {};
            payload.data["isEscPortal"] = $scope.data.portalSysId === '70cd9f3b734b13001fdae9c54cf6a72f';
            payload.data["portalSuffix"] = $scope.data.portalSuffix;
            payload.data["Number"] = number;
            payload.data["Action"] = action;
            snAnalytics.addEvent(payload);
        }
    }
});
7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@Nani5 

how are you getting that sysId in server side?

you can access the URL itself in client side and get the sysId if it's present in url parameter

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi @Ankur Bawiskar 

Thanks for your response.

Below is the URL I am trying to make dynamic,in that the last parameter is sysid where I am getting in server code highlighted(in orange).

But when I  tried to call that URL from server to client I am stuck,data and $scope.data are not working or I am missing something!!

URL:

var surveyURL ="./assessment_take2.do?sysparm_assessable_type=8836b8f61b1438103c6321f5604bcbb1&sysparm_assessable_sysid=d86c6a363bc92e540b70859aa4e45a74";
var answer=  window.open(surveyURL, "_blank");
Server side:
var closeSurveyURL='';
var gr = new GlideRecord('incident');
gr.addQuery('sys_id', sys_id);
gr.query();
if (gr.next()) {
    gr.incident_state = State;
    if (gr.update() == null) {
        gs.addErrorMessage(errorMessage);
    } else {
        gs.addInfoMessage(infoMessage);
    }
    var assesRecSnew GlideRecord('asmt_assessment_instance');
            assesRecS.addEncodedQuery('stateINready,wip^trigger_id=' + gr.sys_id.toString());
            assesRecS.orderByDesc("sys_created_on")  ;
            assesRecS.query();
            if (assesRecS.next()) {
                //data.incCloseSurvey = true;
                closeSurveyURL = "./assessment_take2.do?sysparm_assessable_type=" +assesRecS.metric_type+ "&sysparm_assessable_sysid="+assesRecS.sys_id;                
            }
}
Normally how can we call server code in client side in "Action type"(sn_ex_sp_action_type) record?
 

@Nani5 

why not get the URL in client side and get sysId from there

var url = window.location.href;

// then get the sysId from that URL using string manipulation

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi @Ankur Bawiskar 

I tried doing that aswell.That is giving current url i.e ESC page url.But I need assessment sys_id in that URL which will not generate until I click on the button.

I tried by using Glide Ajax,data object and also $scope like we use in widgets but since it is different configuration i.e Action type,it's not working.

Is there a way in the Action type to call the server variable in Client?

Correct me if I am wrong!!