Business Rule is not working to set Requestor details in the RITM table once the request is created

RamyaShreeA
Giga Contributor
(function executeRule(current, previous /*null when async*/) {

    // Add your code here
        var EmployeeType;
    var RequesterLocationType;
    var Grade;
    var BUName;
    var IRM;
    var LocationID;
    var Location;
    var sysid;
    var EmpName;


var Psno=current.variables.RequesterPsno; //gs.getUserName();/

var UserTable = new GlideAggregate('sys_user');
    UserTable.addQuery('user_name',Psno);
    UserTable.query();
    if (UserTable.next())
    {
        Grade= UserTable.getValue('u_grade');
        EmpName=UserTable.getValue('name');
       
        BUName =  UserTable.getValue('u_deputed_bu');
        LocationID = UserTable.getValue('u_current_location_code');
        Location =  UserTable.getValue('u_psa_text');
        sysid = UserTable.getValue('sys_id');
        var UserTable1 = new GlideAggregate('sys_user');
        UserTable1.addQuery('sys_id',UserTable.u_supervisor_id);
        UserTable1.query();
        if (UserTable1.next())
        {
            IRM = UserTable1.user_name;
        }
   
        var isnum = /^\d+$/.test(UserTable.u_current_location_code);
        if(isnum==true){
            EmployeeType = 'LTI';
            RequesterLocationType='LTI';
        }
        else{
            EmployeeType = 'M';
            RequesterLocationType='M';
           
        }

    current.variables.EmployeeType=EmployeeType ;
    current.variables.RequesterLocationCode=LocationID ;
    current.variables.RequesterLocation=Location;
    current.variables.RequesterLocationType=RequesterLocationType;

    current.variables.Requestername=EmpName;

//  current.variables.SelfOther',localInput.SelfOther);

    current.variables.RaisedByName=EmpName;
    current.variables.RaisedByPs=RequesterPsno;
   
    current.variables.RequestersIRMPs=IRM;
    current.variables.RequesterBU=BUName;
    current.variables.RequesterGrade=Grade;
    current.variables.Status=1 ;

    /*current.variables.VisitStartDateDatetime=''
    current.variables.VisitStartDate=''
    current.variables.VisitEndDateDatetime=''
    current.variables.VisitEndDate=
    current.variables.VisitDuration =
    current.variables.RequestedDatetime=
   
*/
    current.update();


    }

    //setting to requester details to accomm on behalf
        var sc_req = new GlideAggregate('sc_request');
        sc_req.addQuery("number",request1);
        sc_req.query();
        if(sc_req.next()){
           
            //setting to requester details to accomm on behalf
            sc_req.requested_for=sysid;
            sc_req.opened_by=sysid;
            sc_req.sys_created_by=Psno;
            sc_req.update();
        }
    var req_item = new GlideAggregate('sc_req_item');
        req_item.addQuery('request.number='+request1);
        req_item.query();
        if(req_item.next()){
           
            //setting to requester details to accomm on behalf
            req_item.requested_for=sysid;
            req_item.opened_by=sysid;
            req_item.sys_created_by=Psno;
           
            req_item.stage='waiting_for_approval';
            req_item.update();
            //notification trigger
            var answer = [];
            var grloc = GlideAggregate('u_locationadminpersonal');
            grloc.addQuery('u_processtype=Temporary Access Card^u_unlimitedapproval=Yes^u_locationequivalentcodeSTARTSWITH'+current.variables.VisitingLocation);
            grloc.query();
            while(grloc.next()){
                var GrpManager=''+grloc.getValue('u_psnumber');
                var grUser = new GlideAggregate("sys_user");
                grUser.addQuery("user_name",GrpManager);
                grUser.query();
                if(grUser.next())
                {
                    answer.push(''+grUser.sys_id);
                }
            }
           
            //if location in mysore LTI add Ashrith and Akarsh as recipients //mysore
            if(current.variables.VisitingLocation=='Mysore'){
                answer.push('akarsh.shetty@ltimindtree.com');
                answer.push('ashrith.urs@ltimindtree.com');
                answer.push('Nuthan.Gowda@ltimindtree.com');
            }
           
           
            var answer1 = [];
            var usertbl = new GlideAggregate('sys_user');
            usertbl.addQuery('user_name',Psno); //TO: requester//send from client
            usertbl.query();
            if (usertbl.next()){
                answer1.push(''+usertbl.sys_id);
            }
            //event call for notification
            gs.eventQueue("temporaryidcard.submitted", current, answer,answer1);            
        }



})(current, previous);
0 REPLIES 0