Get RITM number from sc_task client script

kshaw
Giga Guru

I have a client script running on sc_task table. I need to get the RITM number to pass to a Glide Ajax call.

I am using "var ritm = g_form.getValue('current.request_item.number');" but it is not returning a value.

What am I coding wrong or incorrect dot walking in line 6.

 

whole script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var status = g_form.getValue('current.variables.comp_reviewStatus');
	var ritm = g_form.getValue('current.request_item.number');
	alert("The selected reveiw status is " + status + " for " + ritm);
	var ritmStatus;
    
	switch (status) {
        case "under_review":
            ritmStatus = 2; // state = Work in Progress
			alert("On the Under Review branch");
            break;
        case "awaiting_client":
            ritmStatus = 5; // state = Awaiting Client
			alert("On the Awaiting Client branch");
            break;
        case "job_builder":
            ritmStatus = 18; // state = Awaiting Job Builder
			alert("On the Awaiting Job Builder branch");
            break;
        case "completed":
            ritmStatus = 2; // state = Work in Progress
			alert("On the Completed branch");
            break;
    }
	
	// ajax script call to set State on RITM
	var setState = new GlideAjax('SHR_set_RITM_State');
    gaTitle.addParam('sysparm_name', 'setState');
    gaTitle.addParam('sysparm_ritm', ritm);
	gaTitle.addParam('sysparm_status', ritmStatus);
    //gaTitle.getXML(Job_Answer);
}

 

1 ACCEPTED SOLUTION

Akif_Shah
Kilo Sage
Kilo Sage

Totally agree with the above comment. In addition to that you can also use getReference if you need the RITM Number

g_form.getReference("request_item", getRITMNumber);

function getRITMNumber(ritms){
      var ritm = ritms.number;
      var status = g_form.getValue("comp_reviewStatus");

      alert("The selected review status is " + status + " for " + ritm);}

View solution in original post

5 REPLIES 5

-O-
Kilo Patron
Kilo Patron

If you are calling a GlideAjax endpoint anyway, you can just move the logic to get the RITM based on the Catalog Task into the client callable Script Include.

As for your script, there is no current client side, and one cannot dot-walk client side.

To get the RITM number, or any information about it, you have two options:

- add the needed field to the form (hide it with a UI Policy if not really needed or in the way) and then you can just use g_form.getValue() or

- add the info to the scratchpad in a display business rule.

Akif_Shah
Kilo Sage
Kilo Sage

Totally agree with the above comment. In addition to that you can also use getReference if you need the RITM Number

g_form.getReference("request_item", getRITMNumber);

function getRITMNumber(ritms){
      var ritm = ritms.number;
      var status = g_form.getValue("comp_reviewStatus");

      alert("The selected review status is " + status + " for " + ritm);}

Thanks for your response. I changed up my client script to use your function, added a switch to deal with status and then a GlideAjax call to a script include to update the sc_req_item record.

Working now.

Thanks

 

Benlem
Tera Expert

You cannot use current in a client script. It's a variable from a Business Rule. 

 

You could use g_form.getUniqueValue() to get the sys_id of this record. Then put it into a Ajax param and request the RITM with a Glide Record in your Script Include.