Adding function to script include

Primm
Tera Contributor

Hello,

I need help inputting these functions into this existing Script Include. I tried to do it but it was not working. The purpose of this is create a task for a group called OGC when it is assigned to them.

 

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

        validateUser: function() {
                var inGroup;
                var obj = gs.getUserID();
                var group = this.getParameter('sysparm_group_name');
                var gr = new GlideRecord("sys_user_grmember");
                gr.addEncodedQuery('group='+group+'^user='+obj);
                gr.query();
                if(gr.next())
                        inGroup = true;
                else
                        inGroup = false;
               
                this.getRootElement().setAttribute('inGroup', inGroup);
        },

        /*
        *Description:
        *Function that can be used to create a OGC Intake record from another record.  Also will
        *move the initial record's attachments to the new OGC Intake.
        *
        *Parameters:
        *requested_by: The sys_id of the Requested by user.
        *short_description: The desired Short Description for the OGC Intake
        *description: The desired Description for the OGC Intake
        *sourceRecordTable: The table name of the source record
        *sourceRecordID: The source record sys_id
        *
        *Return:
        *Returns the sys_id of the created OGC Intake record.

        */
        createOGCRecord: function(requested_by, short_description, description, sourceRecordTable, sourceRecordID) {
                var ogcGR = new GlideRecord('x_g_duas_ogc_intake');
                ogcGR.initialize();
                ogcGR.requested_by = requested_by;
                ogcGR.short_description = short_description;
                ogcGR.description = description;
                ogcGR.insert();

                //Copy attachments
                var attachment = new GlideSysAttachment();
                var copiedAttachments = attachment.copy(sourceRecordTable, sourceRecordID, 'x_g_duas_ogc_intake', ogcGR.getUniqueValue() + '');

                return ogcGR.getUniqueValue() + '';
               
        },
  
        type: 'ogcUtil'
});


New functions:

Call the createOGCRecord function with the following parameters:
    requested_by: The sys_id of the Requested by user.
    short_description: The desired Short Description for the OGC Intake
    description: The desired Description for the OGC Intake
    sourceRecordTable: The table name of the source record
    sourceRecordID: The source record sys_id

This method will return the sys_id of the generated OGC Intake record.

*NOTE:  When calling this from another application scope, it may be necessary to define cross-scope access or restricted caller access entries to allow the applications to interact properly.

2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@Primm Could you please try the following.

 

 

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

        validateUser: function() {
                var inGroup;
                var obj = gs.getUserID();
                var group = this.getParameter('sysparm_group_name');
                var gr = new GlideRecord("sys_user_grmember");
                gr.addEncodedQuery('group='+group+'^user='+obj);
                gr.query();
                if(gr.next())
                        inGroup = true;
                else
                        inGroup = false;
               
                this.getRootElement().setAttribute('inGroup', inGroup);
        },

        /*
        *Description:
        *Function that can be used to create a OGC Intake record from another record.  Also will
        *move the initial record's attachments to the new OGC Intake.
        *
        *Parameters:
        *requested_by: The sys_id of the Requested by user.
        *short_description: The desired Short Description for the OGC Intake
        *description: The desired Description for the OGC Intake
        *sourceRecordTable: The table name of the source record
        *sourceRecordID: The source record sys_id
        *
        *Return:
        *Returns the sys_id of the created OGC Intake record.

        */
        createOGCRecord: function(requested_by, short_description, description, sourceRecordTable, sourceRecordID) {
                var ogcGR = new GlideRecord('x_g_duas_ogc_intake');
                ogcGR.initialize();
                ogcGR.requested_by = requested_by;
                ogcGR.short_description = short_description;
                ogcGR.description = description;
                var ogcGRSYSID = ogcGR.insert();

                //Copy attachments
                var attachment = new GlideSysAttachment();
                var copiedAttachments = attachment.copy(sourceRecordTable, sourceRecordID, 'x_g_duas_ogc_intake', ogcGRSYSID+ '');

                return ogcGRSYSID + '';
               
        },
  
        type: 'ogcUtil'
});

 

Hope this helps.

Thanks. It didn't work.

 

I'm trying to see if I can go the business rule route. 

My code isn't working though.

 

(function executeRule(current, previous /*null when async*/) {

    // Add your code here
    var ogcUtil = new x_g_duas_ogc.ogcUtil();
    ogcUtil.createOGCRecord(current.getValue('requested_by'),
    current.short_description,
    current.description,
    current.getRelatedTables,
    current.sys_id,
    );


})(current, previous);
 

Call the createOGCRecord function with the following parameters:
    requested_by: The sys_id of the Requested by user.
    short_description: The desired Short Description for the OGC Intake
    description: The desired Description for the OGC Intake
    sourceRecordTable: The table name of the source record
    sourceRecordID: The source record sys_id

This method will return the sys_id of the generated OGC Intake record.