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

Michael Fry1
Kilo Patron

What doesn't work? You mentioned Agent Workspace and Service Portal but you don't mention what's not working and where.

If you made answers 1-3 mandatory fields, you could probably eliminate most of this script since all you're doing is setting a date.

In this particular case when checking or unchecking the "Verified" checkbox the logic for the addErrorMessage and setValue for date and time do not work.

We could make the answers mandatory fields however they are set as read only. The agent taking the call/interaction should only be able to read the answers and not set them. If the caller/opened_by user do not have the answers filled in then the agent cannot proceed to take the call/interaction. This is specific to our business processes, hence the verification. The agent is instructed to ask a question that must be verified against one of the answers the caller/opened_by user has on their account.

Hope this helps clarify.

Right now I think my problem is that I cannot get the getReference & addErrorMessage methods working on the workspace. Everything I try it comes back as undefined.

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

g_form.addErrorMessage(open_for.name + ' ....');

Stefan K_
Tera Expert

Frankly, I am surprised to see these questions where you have managed to produce a fairly advanced script but then just present the whole script and ask why it is not working.

Logging, logging, logging has always been the answer to debug a script instead of just eye balling it and thinking what might go wrong. 

You start logging from top and verify that your variables get the values you expect, the code goes correctly to the IF statements etc. It's really the only way.