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

Hi @sry ,

put a gs.info() inside the updateCI method and check if the method is being called or not

 

please share the screenshots of UI action and the script include configurations

 

may the from the scope it doesn't have access to cmdb_ci_hardware table

 

put this script in the background script with test values and check 

set sysid of CI and field name and value and select your scope if available for test

new global.InsertXYZRecord().updateCI(current.getValue('SYSID OF A CI'),'short_description'/*fieldName*/,'value');

ChaitanyaILCR_1-1748980894033.png

 

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

Regards,
Chaitanya

Hi Chaitanya, i am able to call the script include and the function. One small issue is as you can see in the function i am hardcoding that "SYS_UPDATED_BY" = 'oreo'. System is not setting the value 'oreo', it is populating the user who made the update. how can i circumvent this?

 grCI.sys_updated_by='oreo';

 

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

 

Thank you so much Chaitanya. i am able to resolve the issues and everything is working as we expected.