How to set requested for value as variable value

BanuMahalakshmi
Tera Contributor

Hi, could you pls assist me to setup request for field value as Service Request Variable Value in service portal-

In service Request form, we have variable - New service account name, single line text field.

After submission of this service request form, Requested for variable display the value of new service account name variable value.

(requested for is out of the box variable, logic is picking up the submitted by user name.)
Please assist me to reflect new service account name into Request for.

 

For Example:

BanuMahalakshmi_0-1726232276477.png

 

1 REPLY 1

Rajesh Chopade1
Mega Sage

Hi @BanuMahalakshmi 

You can achieve this by using 'catalog client script' or 'flow designer / workflow'.

Catalog client script:

- create 'OnSubmit' catalog client script (or OnChange if applicable)

- write script where capture value from your variable 'account name' and store it desired variable (requested for) using script include.

- client script :

function onSubmit() {
    // Assuming 'new_service_account_name' is the variable name
    var newServiceAccountName = g_form.getValue('new_service_account_name');

    // Save this value to a hidden field or send it to the server
    g_form.setValue('u_new_service_account_name', newServiceAccountName);

    // Optional: You can also use AJAX to send data to the server
    var ga = new GlideAjax('UpdateRequestWithVariable');
    ga.addParam('sysparm_name', 'updateRequest');
    ga.addParam('sysparm_request_id', g_form.getValue('request_id'));
    ga.addParam('sysparm_new_service_account_name', newServiceAccountName);
    ga.getXMLAnswer(function(response) {
        // Handle response if needed
    });
}

 

script include

var UpdateRequestWithVariable = Class.create();
UpdateRequestWithVariable.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    updateRequest: function() {
        var requestId = this.getParameter('sysparm_request_id');
        var newServiceAccountName = this.getParameter('sysparm_new_service_account_name');

        var request = new GlideRecord('sc_request');
        if (request.get(requestId)) {
            request.u_new_service_account_name = newServiceAccountName;
            request.update();
        }
        return '';
    }
});

 

I hope my answer helps you to resolve your issue if yes please mark my answer helpful and correct.

thank you

rajesh