Skip to content

Get cmdb_ci detail #1096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

at8807602
Copy link
Contributor

This script include helps to get the details of CI selected in Incident table.

@kmxo
Copy link
Contributor

kmxo commented Oct 3, 2024

Hi Abhishek,

I'd use the pattern JSON to return data from the Server side. Something like this:

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

    getCI: function() {
        var ci = this.getParameter("sysparm_cmdb_ci");
        var cmdb = new GlideRecord("cmdb_ci");
        cmdb.addQuery("sys_id", ci);
        cmdb.query();
        if (cmdb.next()) {

            var results = {
                "sys_id": ci,
                "name": cmdb.name.toString(),
                "asset_tag": cmdb.asset_tag.toString(),
                "serial_number": cmdb.serial_number.toString()
                
            };

            return JSON.stringify(results);

        }
    },

    type: 'GetCI_Details'
});

Then use it from a Client side (Client Script or Catalog Client Script) to populate a field like this.
You can show how to use it within your readme.md file:

function onLoad() {

    //It is Hacktoberfest'24!
    var ga = new GlideAjax('GetCI_Details');
    ga.addParam('sysparm_name', 'getCI');
    ga.addParam('sysparm_cmdb_ci', 'b4fd7c8437201000deeabfc8bcbe5dc1');
    ga.getXMLAnswer(callback);

}

function callback(answer) {
    var clearvalue; 
    if (answer) {
        var returneddata = JSON.parse(answer);
	//console.log(returneddata);
	g_form.setValue("cmdb", returneddata.name);
    } else {
        g_form.setValue("cmdb", clearvalue);
    }
}

Thank you.

@kmxo kmxo closed this Oct 3, 2024
@kmxo kmxo self-assigned this Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants