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

Saurav11
Kilo Patron
Kilo Patron

Hello,

If there is no field called field type why are you updating it?

What is your aim exactly from this script?

Which field needs to be updated and in which table does it contain?

Please answer the above questions so that i can help you

Hope this helps. Please mark the answer as correct/helpful based on impact.

Okay.

We have a field caller server name, The user enter the server name.

We also have a couple of fields like assigned to, assignment group, manager name, asset... which are check boxs and each checkbox has a single line, reference fields which shows up on checking the checkbox.

The user enters the new value that needs to be updated with respect to the server name on to the fields.

They fill the details and submit the catalog.

Table to be updated: cmdb_ci

 

Hope this answers your question.

Hello Hari,

I understood the first part, for the second part are there corresponding fields for each catalog field on cmdb table ot there is only on field on cbdm table and you are trying to concat all the three fields into one?

Hi Saurav,

Each checkbox has a individual single line, reference fields associated with the checkbox and each single line or reference field names that are on the catalog are exactly named after the fields that are on the cmdb_ci table so it will be easy to updated based on the checkbox selection.