diff --git a/Server-Side Components/Script Includes/Get Already Associated Records/README.md b/Server-Side Components/Script Includes/Get Already Associated Records/README.md new file mode 100644 index 0000000000..76c354589b --- /dev/null +++ b/Server-Side Components/Script Includes/Get Already Associated Records/README.md @@ -0,0 +1,3 @@ +We can use javascript to build a query and inside that script we can call a script include to fetch already associated records which we can utilize in other logic. + +image diff --git a/Server-Side Components/Script Includes/Get Already Associated Records/getAlreadyAssociatedRecords.js b/Server-Side Components/Script Includes/Get Already Associated Records/getAlreadyAssociatedRecords.js new file mode 100644 index 0000000000..4e1410c96f --- /dev/null +++ b/Server-Side Components/Script Includes/Get Already Associated Records/getAlreadyAssociatedRecords.js @@ -0,0 +1,22 @@ +//Check if there is already record existing for a particular Issue to Item. + +var getAlreadyAssociatedRecords = Class.create(); +getAlreadyAssociatedRecords.prototype = Object.extendsObject(global.AbstractAjaxProcessor, { + + getSysIdsItem: function(issueId) { + + var alreadyAssociatedContent = []; + var gr = new GlideRecord('sn_grc_m2m_issue_item'); + gr.addQuery('sn_grc_issue', issueId); + gr.query(); + + while (gr.next()) { + if (!gr.sn_grc_item.nil()) + alreadyAssociatedContent.push(gr.getValue('sn_grc_item').toString()); + } + return alreadyAssociatedContent.join(','); + + }, + + type: 'getAlreadyAssociatedRecords' +});