Question on Script Include insert record

Meera_P
Tera Expert

Hello,

I' am currently in the process of learning JavaScript. If my question isn't clear, please feel free to ask for clarification.

I have an UI Action that calling Script Include to create a new record in approval table.  I got stuck on how to insert the assigned group in the approval table. I am seeking for the the community for help.  Thank you

 

UI Action:

 

function requestApproval() {
    var approverSysId = g_form.getValue('assigned_to');
    var recordSysId = g_form.getUniqueValue();
	var assignedGroup = g_form.getValue('assigned_group');
	g_form.save();

    var ga = new GlideAjax('NewApprovalRecord');
    ga.addParam('sysparm_name', 'createApprover');
    ga.addParam('sysparm_approver', approverSysId); //Approver SysID
    ga.addParam('sysparm_sys_id', recordSysId); //changeSysID
	ga.addParam('sysparm_assignedGroup',assignedGroup); 
    ga.getXMLAnswer(callBackFunction);
}

function callBackFunction(values) {
  alert(values);
}

 

 

Script Include:

 

var NewApprovalRecord = Class.create();
NewApprovalRecord.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    createApprover: function() {

        var approverID = this.getParameter('sysparm_approver');
        var recordID = this.getParameter('sysparm_sys_id');
        var assignedGroup = this.getParameter('sysparm_assignedGroup');

        var newApproval = new GlideRecord('sysapproval_approver');
        newApproval.initialize();
        newApproval.setValue('state', 'requested');
        newApproval.setValue('approver', approverID);
        newApproval.setValue('sysapproval', recordID);
        newApproval.setValue('assigned_group', assignedGroup);
        newApproval.insert();

        var values = newApproval.getUniqueValue();
     
        return values;
    },
    type: 'NewApprovalRecord'
});

 

 

Results:

Meera_P_0-1718913578552.png

 

1 ACCEPTED SOLUTION

johnfeist
Mega Sage
Mega Sage

Hi Meera_P,

 

Are you trying to create both a group approval and an individual approval?  Group approvals are recorded in sysapproval_group.  There is no assigned_group in sysapproval_approver.  I suspect that you are getting an error on the statement where you are trying to assign a value to assigned_group which is stopping processing and not inserting anything.  If all you need is one approver, you don't need to do anything for group.  If on the other hand you want to create a group approval, you need to do the insert into that table.

 

The fastest way to debug your script include is to modify it so that you can call it directly passing the arguments that would be the parms via AJAX.  That way, you can run it through the script debugger and see what is happening.

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

View solution in original post

2 REPLIES 2

johnfeist
Mega Sage
Mega Sage

Hi Meera_P,

 

Are you trying to create both a group approval and an individual approval?  Group approvals are recorded in sysapproval_group.  There is no assigned_group in sysapproval_approver.  I suspect that you are getting an error on the statement where you are trying to assign a value to assigned_group which is stopping processing and not inserting anything.  If all you need is one approver, you don't need to do anything for group.  If on the other hand you want to create a group approval, you need to do the insert into that table.

 

The fastest way to debug your script include is to modify it so that you can call it directly passing the arguments that would be the parms via AJAX.  That way, you can run it through the script debugger and see what is happening.

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

Hi @johnfeist 

Thank you so much for the explanation. My code is functioning well without the assignment group included.  Initially, I didn't understand how it worked, but I do now.  Thank again!