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

@Nani5 

please share your complete widget code

HTML, Client Controller, Widget

what's your business requirement exactly?

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 

It's not a Widget.The requirement is the "close with survey button" should open the survey quetions page and once user fills the survey and submit the incident should be automatically closed.

It is under to-do's page and for this the configuration is done in "sn_ex_sp_action_type" under to-do's configuration.

Below is the screenshot for your reference and the code is already shared above .This has only server script and Client script but no CSS and HTML like widget. 

@Nani5 

this link should help you -> try this {table.sys_id}

Custom sn_ex_sp_task_configuration 

Also check any OOTB ones and how the sysId is passed

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