How to concat a variable value to the GlideRecord?

Hari1
Mega Sage

Hi,

I have a catalog client script which is passing the table field name (assignment_group) to the script include.

On the script include i have queried the table and i am trying to update the new field value.

Client Script:

var ajax = new GlideAjax('UpdateCMDBFieldValues'); //Script Include Name
ajax.addParam('sysparm_name', 'updateField'); // Function Name
ajax.addParam('sysparm_value', getList);      // Server Name
ajax.addParam('sysparm_value2', storeValue);  // Assignment Group Sys_id
ajax.addParam('sysparm_value3', fieldName);   // Name of the field (assignment_group)
ajax.getXML(getReturnValue);

function getReturnValue(answer) {
        alert("Inside getReturnValue");
    }

Script Include:

var pushedValue = this.getParameter('sysparm_value'); // Server Name
var newValueToUpdate = this.getParameter('sysparm_value2'); //Assignment Group Sys_id
var fieldType = this.getParameter('sysparm_value3'); // Field Name (assignment_group)

var gr = new GlideRecord("cmdb_ci");
gr.addQuery('name', pushedValue );
gr.query();
if (gr.next()) {
gs.log("BNG - inside if block of gr.next()");
gr.fieldType = newValueToUpdate;
gr.update();
}

The problem is with the line gr.fieldType as the table "cmdb_ci" does not have a field name called "fieldType" it is not able to updated the assignment_group.

As the fieldType variable has the value "assignment_group".

Can you please help me find a way to concat or convert the fieldType variable into assignment_group?

1 ACCEPTED SOLUTION

Anurag Tripathi
Mega Patron
Mega Patron

Try to use gr.setValue('field_name',value )  and pass trhe field name and value here .

 

-Anurag

View solution in original post

9 REPLIES 9

Hi Saurav,

We just have to figure out if we can concate a variable value with the GlideRecord as below.

gr.fieldType = newValueToUpdate;

As the variable fieldType will store the value "assignment_group" which is the field name that is passed from the client script to the script include. Please refer the above code for more details.

Gaurav Shirsat
Mega Sage

Hello

Call Back Function is Missing in Your Client Script.

Syantax:-   var ans = response.responseXML.documentElement.getAttribute("answer");

refer

Mark my Response as Correct or Helpful, if you find it Appropriate.
Gaurav Shirsat
https://www.linkedin.com/in/gauravshirsat/

Hi,

Yes, We do not want any return values back from the script include.

So we do not use.

var ans = response.responseXML.documentElement.getAttribute("answer");

Anurag Tripathi
Mega Patron
Mega Patron

Try to use gr.setValue('field_name',value )  and pass trhe field name and value here .

 

-Anurag

Hi Anurag,

Works like a charm. Thanks a lot.