Agent Workspace Client Scripts (getReference not working)

NFGDom
Mega Sage

Hello!

We're moving from the Caller's Module to Interactions and plan to use the Agent Workspace. However we have some company specific requirements when identifying users. I'm curious if someone can take a look at my client script to see what I'm missing. In the native ui it works fine but in the Agent Workspace not so much. I have verified the methods I'm calling to make sure they work with the Agent Workspace but it seems that I'm missing something.

Here is my client script:

find_real_file.png

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   //Type appropriate comment here, and begin script below
   //alert('You changed Security Phrase Verified from ' + oldValue + ' to ' + newValue);
    //g_form.u_nf_security_verified_date_time = ;

    var verified_value = g_form.getValue('verified');
    var open_for = g_form.getReference('opened_for');
    var answer1 = g_form.getValue('interaction.opened_for.u_nf_security_phrase');
    var answer2 = g_form.getValue('interaction.opened_for.u_nf_security_phrase_2');
    var answer3 = g_form.getValue('interaction.opened_for.u_nf_security_phrase_3');
    //alert(open_for);

    if (answer1 == "" && answer2 == "" && answer3 == "") {
        g_form.addErrorMessage(open_for.name + ' does not have their answers filled out. Please instruct ' + open_for.name + ' to the "Infonet > E-Docs > Information Technology > Help Desk Identification Survey". ' + open_for.name + ' can have a verified colleague call on their behalf if needed.');
        if (verified_value == "true") {
            g_form.setValue('verified', false);
        }
    } else {
        if (verified_value == "true") {
            //alert("Value is true");
            //get the current date and time
            var ajax = new GlideAjax('ClientDateTimeUtils');
            ajax.addParam('sysparm_name', 'getNowDateTime');
			//call function to set date and time field
            ajax.getXML(doSomething);
        } else {
            //alert("value is false");
            g_form.setValue('u_nf_hdiq_verified_date_time', null);
        } //end if statement
    } //end of else statement

    //set the current date and time on the field
    function doSomething(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        //alert(answer);
        g_form.setValue('u_nf_hdiq_verified_date_time', answer);
    } //end get date time function
}

 

In addition I'm curious if there are some cheat sheets, useful links, or information when using client scripts for Service Portals for best practices on what methods to use and what will/won't work against the native ui. 

Thanks in advance!

Dom

1 ACCEPTED SOLUTION

Prasad Pagar
Mega Sage

Hi @NFGDom 

var open_for = g_form.getReference('opened_for');

where is your callback function??

find_real_file.png

also your script include name is 'getNowDateTime' ??

Thank you
Prasad

View solution in original post

8 REPLIES 8

Understandable and understood. I think my biggest confusion is what is supposed to work for the Native UI vs the Portal in client scripts. Then I read documentation like this and see I have methods that should be working but I'm still getting undefined values in the debugger.

Prasad Pagar
Mega Sage

Hi @NFGDom 

var open_for = g_form.getReference('opened_for');

where is your callback function??

find_real_file.png

also your script include name is 'getNowDateTime' ??

Thank you
Prasad

Hi Prasad,

Turns out this is what I was missing and was able to get my script to work.

I wasn't aware (until now) that in the Portal you need a callback function for getReference and overlooked it on the docs. In the Native UI I haven't needed a callback yet for this use.

Thank you for the response and help!

Glad that its fixed 🙂

Happy Learning

Thank you and Stay Safe
Prasad