Extending the OOB Script include

Janu sree
Tera Guru

I've to modify a function(getBadgingDetails: function(finalTodoArray))  in OOB script include which is not Read-only. I've gone through few docs stating that for Best Practice we have to extend and override this function in new script include. I somehow tired doing this but its not working, Any suggestions on this ? OOB SI is on Employee centre core application and has caller access. I'm not sure if I'm doing correct steps here or not as this is my first time on this.
Should check through this extended SI first if this satisfies the conditions then it should execute the SI here or it should execute the function in OOB script include.(as there are other TO-do as well which is using this OOB script include)

Function in OOB script include:

_getBadgingDetails: function(finalTodoArray) {
for (var index = 0; index < finalTodoArray.length; index++) {
var currentElemDueDate = finalTodoArray[index].sys_id;
var badgeBadgeColorArr = this._getDueDateForBadge(currentElemDueDate);
finalTodoArray[index].badge = badgeBadgeColorArr[0];
finalTodoArray[index].badgeColor = badgeBadgeColorArr[1];
finalTodoArray[index].badgeTextColor = badgeBadgeColorArr[2];
}
return finalTodoArray;
},
// get the due date text and badge colours
_getDueDateForBadge: function(dueDate) {
var dueDateBadgeBadgeColor = [];
var dueDateDisplayValue = "";
var dueDateDisplayColor = "";
var dueDateTextColor = "";
if (!gs.nil(dueDate)) {
var dueDays = this._getDueDays(dueDate + '');
if (dueDays < 0) {
if (dueDays === -1)
dueDateDisplayValue = gs.getMessage('Overdue {0} day', String(0 - dueDays));
else
dueDateDisplayValue = gs.getMessage('Overdue {0} days', String(0 - dueDays));
dueDateDisplayColor = "#FFCCD2";
} else {
if (dueDays < 7) {
if (dueDays === 0)
dueDateDisplayValue = gs.getMessage('Due today');
else if (dueDays === 1)
dueDateDisplayValue = gs.getMessage('Due soon in {0} day', dueDays);
else
dueDateDisplayValue = gs.getMessage('Due soon in {0} days', dueDays);

dueDateDisplayColor = "#FBF7BC";
} else if (dueDays >= 7) {
dueDateDisplayValue = gs.getMessage('Due in {0} days', dueDays);
dueDateDisplayColor = "#CBE9FC";
}
}
} else {
dueDateDisplayValue = gs.getMessage('No due date');
dueDateDisplayColor = "#CBE9FC";
}
dueDateTextColor = "#181A1F";
dueDateBadgeBadgeColor[0] = dueDateDisplayValue;
dueDateBadgeBadgeColor[1] = dueDateDisplayColor;
dueDateBadgeBadgeColor[2] = dueDateTextColor;

return dueDateBadgeBadgeColor;
},


Name of OOB script include - todoPageUtils
Below is the new script include which I created and extended. This script which I've customized 

 

var todoextendedSI = Class.create();

todoextendedSI.prototype = Object.extendsObject(todoPageUtils, { //name of OOb SI

   

   //function from OOB script include which I have modified and included here

    _getBadgingDetails: function(finalTodoArray) {

        for (var index = 0; index < finalTodoArray.length; index++) {

            var currentElemDueDate = finalTodoArray[index].sysId;

            var badgeBadgeColorArr = this._getDueDateForBadge(currentElemDueDate);

            finalTodoArray[index].badge = badgeBadgeColorArr[0];

            finalTodoArray[index].badgeColor = badgeBadgeColorArr[1];

            finalTodoArray[index].badgeTextColor = badgeBadgeColorArr[2];

        }

        return finalTodoArray;

    },

    // get the due date text and badge colours

    _getDueDateForBadge: function(sysId) {

        var dueDateBadgeBadgeColor = [];

        var dueDateDisplayValue = "";

        var dueDateDisplayColor = "";

        var dueDateTextColor = "";

        //var getapp = new GlideRecord('sysapproval_approver');

        var getapp = new GlideRecord('sysapproval_approver');

        getapp.get(sysId);

        // getapp.addQuery('state', 'requested');

        // getapp.query();

        // if (getapp.next()) {

        if (getapp.source_table == 'kb_knowledge') {

            var getapp1 = new GlideRecord('kb_knowledge');

            getapp1.addQuery('sys_id', getapp.document_id);

            getapp1.query();

            if (getapp1.next()) {

                if (getapp1.workflow_state == 'review') {

                    gs.info('getreview:' + getapp1.number + dueDateDisplayValue + getapp1.workflow_state);

                    dueDateDisplayValue = gs.getMessage('KB PUBLISH APPROVAL');

                    dueDateDisplayColor = "#FBF7BC";

                    //return dueDateDisplayValue;

                } else if (getapp1.workflow_state == 'pending_retirement') {

                    gs.info('getretiresi:' + getapp1.number + dueDateDisplayValue + getapp1.workflow_state);

                    dueDateDisplayValue = gs.getMessage('KB PENDING RETIREMENT');

                    dueDateDisplayColor = "#CBE9FC";

                    // return dueDateDisplayValue;

                }

            }

        } else if (getapp.source_table == 'change_request') {

            gs.info('getchang:' + getapp.number);

            dueDateDisplayValue = gs.getMessage('Change Approval');

            dueDateDisplayColor = "#FBF7BC";

        } else if (getapp.source_table == 'sc_req_item') {

            gs.info('getrequ:' + getapp.number);

            dueDateDisplayValue = gs.getMessage('Request Approval');

            dueDateDisplayColor = "#FFFFFF";

        }

        dueDateTextColor = "#181A1F";

        dueDateBadgeBadgeColor[0] = dueDateDisplayValue;

        dueDateBadgeBadgeColor[1] = dueDateDisplayColor;

        dueDateBadgeBadgeColor[2] = dueDateTextColor;

   return dueDateBadgeBadgeColor;

    },

type: 'todoextendedSI'

});
5 REPLIES 5

Bert_c1
Kilo Patron

It seems this is a duplicate of an earlier post here. why ask again when there is no response to your previous post? You need to post how you're using the 'todoextendedSI' class.

 

@Bert_c1 - Yes, I want to pass this script include inplace of OOB function. OOB has lot of methods and functions. There is a need for me to modify only in the above function which is from OOB.. I've check through this custom SI first if this satisfies the conditions then it should pass here or it should execute the OOB script include. So suggest me how can I achieve this ? 

TIA.

Hi @Janu sree

 

I can't suggest without seeing how you are calling your custom SI. From what you posted, your SI looks OK.  You can test it from Scripts Background like this.

 

 

var myTodoArray = [];
// load values in the array
var mySI = new todoextendedSI();
var myValues = mySI._getBadgingDetails(myTodoArray);
gs.info(myValues);

 

Good luck.

Thanks for this. It says "todoPageUtils" is not defined. which means It is pointing to the 2 line in the custom script include. Does I have to define anything beside SI name or anything missing ?
Appreciate your efforts