Adding function to script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 02:12 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 08:58 PM - edited 05-30-2024 08:59 PM
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 11:15 AM
Thanks. It didn't work.
I'm trying to see if I can go the business rule route.
My code isn't working though.
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.