Making variable editor editable based on state to opened by user

Hafsa1
Mega Sage

I want variable editor editable for CSM module in portal by "opened by" user in "draft" state.

When I create case via RP , after submit, it create case in "draft" state.

I want every variables to be shown and editable in portal for user. currently only comments is visible

Hafsa1_0-1734494518285.png

 

8 REPLIES 8

I have added but not working

Hafsa1_0-1734499803712.png

 

Hafsa1_1-1734499941198.png

 

@Hafsa1 

Ideally we should not allow end users to edit variables post submission, reason being the flow or workflow associated to it will trigger as soon as RITM is created and might cause issue if you are using the variable in any script

Remember this is an OOB widget and changes you do to this will be impacting every place

Ensure if you update then it happens only for your table records and not for other records

Something like this but please enhance it

Client Controller

(function() {
    function isDraftState() {
        return $scope.data.table === 'sn_customerservice_case' && $scope.data.recordState === 'draft';
    }

    $scope.canEditVariables = function() {
        return isDraftState();
    };
})();

Server Script:

(function() {
    data.table = $sp.getParameter('table') || 'sn_customerservice_case';
    data.sys_id = $sp.getParameter('sys_id');
    data.recordState = getRecordState(data.table, data.sys_id);

    function getRecordState(table, sys_id) {
        var gr = new GlideRecord(table);
        if (gr.get(sys_id)) {
            return gr.state.toString();
        }
        return '';
    }
})();

HTML:

<div ng-if="canEditVariables()">
    <!-- Existing variable editor code -->
</div>
<div ng-if="!canEditVariables()">
    <p>You can only edit variables in the Draft state.</p>
</div>

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

not working, now it is not showing the variable editor in any state

@Hafsa1 

what debugging did you perform?

I already informed the script needs to be enhanced

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader