I have a requirement that. Request type need to based on requested for's role /job title

Raj12341
Tera Contributor

Hello Developers,

I have a requirement that. Request type need to based on requested for's role /job title.

Raj12341_0-1697131469063.png

Raj12341_1-1697131496842.png

Please help me to finish this requiremement.

Thanks.

1 ACCEPTED SOLUTION

@Raj12341 Do you have any further questions on this topic, if not then please mark this answer as solution.

View solution in original post

2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@Raj12341 In order to update the value of Request type field based on the Requested for's role/job title, you need to create an onChange Client script on your catalog item and a script include which will fetch the role/job title of the requestor.

 

Here is the sample code for onChange client script.

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

    //Type appropriate comment here, and begin script below
    var myUtils = new GlideAjax('HRUtils');
    myUtils.addParam('sysparm_name', 'getRequestType');
    myUtils.addParam('sysparm_requested_for', g_form.getValue('requested_for'));
    myUtils.getXML(getRequestTypeResponse);

    function getRequestTypeResponse(response) {		
        var answer = response.responseXML.documentElement.getAttribute("answer");		
		g_form.setValue('request_type', answer);		
    }

}

Here is the server side script for script include, make sure to check client callable checkbox to check on the script incldue

 

var HRUtils = Class.create();
HRUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getSubjectPersonForHRTask: function() {

        var requestedSys_id = this.getParameter('sysparm_requested_for');
        var glideJobTitle = new GlideRecord('<Name of table where title is stored>');
        glideJobTitle.addQuery('user',requestedSys_id);
        var requestType = '';
        if (glideJobTitle.next) {

            if(glideJobTitle.role=='manager'){
             requestType= '<set request type for manager her>'
          }
         //Add similar condition here
        }
        return requestType;
    },

    type: 'HRUtils'
});

 

@Raj12341 Do you have any further questions on this topic, if not then please mark this answer as solution.