Comments on sc_req_item table in scoped application

Onlyprashant
Tera Contributor

Why this code snippet working for one instance and not working on other instance when we have kind of configurations on both instance. I am using it in our custom scoped application on dev instance it is showing all comments of RITM on widget but when i install the application on test instance it is not showing comments there why ? But on test instance if i run this script as background script then it is giving comments but not on widget why ? 

Help me if you have any solution for it.

/**
     * Retrieves journal comments for the RITM and populates data.viewData.comments.
     * @Param {string} ritmId - The unique ID of the RITM.
     */
    function populateComments(ritmId) {
        try {
            var ritmGR = new GlideRecordSecure(IBTableNamesUtility.SC_REQ_ITEM);
            if (!ritmGR.get(ritmId)) {
                return [];
            }

            var allComments = ritmGR.getElement('comments').getJournalEntry(-1);
            if (!allComments) return [];

            // Normalize line endings and split into separate comment blocks
            allComments = allComments.replace(/\r\n/g, '\n');
            var commentBlocks = allComments.split(/\n(?=\d{2}\/\d{2}\/\d{4})/);
            // Splits when a new line starts with a date like 08/12/2025

            var parsedComments = [];

            commentBlocks.forEach(function(block) {
                block = block.trim();
                if (!block) return;

                // Match: date time - author (Additional comments)
                var match = block.match(/^(\d{2}\/\d{2}\/\d{4}\s+\d{2}:\d{2}:\d{2})\s*-\s*(.*?)\s*\((.*?)\)\n([\s\S]*)$/);
                if (!match) return;

                var dateTime = match[1];
                var author = match[2];
                var type = match[3];
                var commentText = match[4].trim();

                // Only include if type is "Additional comments"
                if (type.toLowerCase() === 'additional comments') {
                    parsedComments.push({
                        author: author,
                        time: dateTime,
                        comment: commentText
                    });
                }
            });

            data.viewData.comments = parsedComments;

        } catch (error) {
            data.viewData.comments = [];
        }
    }
2 REPLIES 2

Jamesk
Tera Expert

Have you set up a cross scope privilege on the TEST environment to allow your app to read the RITM table? Cross-scope privilege record 

Yes, I’ve set up the read cross-scope privilege on the RITM table.