global script include not being called from scoped UI action.

sry
Giga Guru

Hi, I am trying to call a Global script include from a scoped UI Action but its not working. Below is the how i am calling from UI action. But its not working. Can anyone help me how can i get the script include being called?

 
I am calling script include "InserXYZRecord" with function "updateCI and passing 3 parameters.
var updateCI = new Global.InsertXYZRecord().updateCI(current.getValue('u_configuration_item'),current.u_attribute_name,current.u_new_value);
Thanks,
Sry
 
 
1 ACCEPTED SOLUTION

Hi @sry 

for that you have to use autoSysFields(false) 

 

update your script include like this 

var InsertXYZRecord = Class.create();
InsertXYZRecord.prototype = {
    initialize: function() {

    },

    updateCI: function(sysId, attributeName, newValue) {
        var grCI = new GlideRecord("cmdb_ci_hardware");
        if (grCI.get(sysId)) {
            grCI.setValue(attributeName, newValue); //updated this line
            grCI.sys_updated_by = 'oreo';
            grCI.setWorkflow(false);
            grCI.autoSysFields(false);
            grCI.update();
        }

    },

    type: 'InsertXYZRecord'
};

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

View solution in original post

8 REPLIES 8

Chaitanya ILCR
Kilo Patron

Hi @sry ,

 

Is your Script Include marked as accessible from all application scopes?

ChaitanyaILCR_0-1748977393836.png

 

 

G in Global should be small

 

var updateCI = new global.InsertXYZRecord().updateCI(current.getValue('u_configuration_item'),current.u_attribute_name,current.u_new_value);

 

after making these changes if still this doesn't work please share screenshot of your script include and code too

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

Hi Chaitanya, thank you for your prompt response. i changed to small letters and it worked. yes the script include has accessible from all application scopes.

However the system called script include function and the function did not work as it supposed to update a record in cmdb_ci_hardware. Below is the script include and its function.

var InsertXYZRecord = Class.create();
InsertXYZRecord.prototype = {
    initialize: function() {

    },
  
    updateCI: function(sysId, attributeName, newValue) {
	var grCI = new GlideRecord("cmdb_ci_hardware");
        grCI.addQuery('sys_id', sysId);
        grCI.query();
        if (grCI.next()) {
            grCI.attributeName = newValue;
	    grCI.sys_updated_by='oreo';
            grCI.setWorkflow(false);
            grCI.update();
        }

    },

    type: 'InsertXYZRecord'
};

 Thanks,

Sry

Hi @sry ,

 

are u passing a field name as a second parameter(attributeName) to the method ?

 

if yes update your script as this

 

var InsertXYZRecord = Class.create();
InsertXYZRecord.prototype = {
    initialize: function() {

    },

    updateCI: function(sysId, attributeName, newValue) {
        var grCI = new GlideRecord("cmdb_ci_hardware");
        if (grCI.get(sysId)) {
            grCI.setValue(attributeName, newValue); //updated this line
            grCI.sys_updated_by = 'oreo';
            grCI.setWorkflow(false);
            grCI.update();
        }

    },

    type: 'InsertXYZRecord'
};

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

Chaitanya, yes i am passing attributeName as second parameter. I changed function in script include but still the UI action is not able to call the script include and its function.

 updateCI: function(sysId, attributeName, newValue) {
	var grCI = new GlideRecord("cmdb_ci_hardware");
        if (grCI.get(sysId)) {
            grCI.setValue(attributeName, newValue);
	    grCI.sys_updated_by='oreo';
            grCI.setWorkflow(false);
            grCI.update();
        }
    },