We are currently experiencing intermittent login issues on Community.  The team is actively working on a fix.

survey

ShubhangiA77524
Tera Contributor

i have a catalog order guide named psra certificate request which when requested generates four ritm for security, vendor,privacy,software so i have a survey and trigger condition is when states changes to closed complete and item is psra certificate request or isdp general inquiry the survey should tigger but it is triggering only for isdp not for psra certificate request and survey should trigger for request on psra

15 REPLIES 15

@ShubhangiA77524  For sc_req_item table you can select items you want to send with OR condition.

 

I believe if you want to do it on request level, you will have to do it through business rule and check if request is part of order guide and then use the assessment API to trigger  the survey.


Please mark the answer correct/helpful accordingly.


Raghav
MVP 2023
LinkedIn

Yes, I want to do it on request level

In this case BR is working but survey is not triggering yet

 

can you share the code?


Raghav
MVP 2023
LinkedIn

(function executeRule(current, previous) {

    
    if (!current.request) return;

    var req = current.request.getRefRecord();

    
    var ritm = new GlideRecord('sc_req_item');
    ritm.addQuery('request', req.sys_id);
    ritm.query();

    var allClosed = true;
    var psra = false;

    while (ritm.next()) {
        
        if (ritm.cat_item.name == 'Security Risk Assessment for Globe Projects and Initiatives' ||
            ritm.cat_item.name == 'Software Assessment Request for Globe Projects and Initiatives' ||
            ritm.cat_item.name == 'Vendor Risk Assessment for Globe Projects and Initiatives' ||
            ritm.cat_item.name == 'Privacy Impact Assessment for Globe Projects and Initiatives') {
            psra = true;
        }

        // Check if any RITM still open
        if (ritm.state != 3) {
            allClosed = false;
        }
    }

    if (!psra || !allClosed) return;

    gs.info('All PSRA RITMs for ' + req.number + ' are closed. Triggering Survey...');

    try {
        
        var surveySysId = '1408df6247d4fed0e9e31e1f116d438e';

     
        var surveyAPI = new GlideRecord('asmt_assessment_instance');
        var instance = new GlideRecord('survey_instance');
        instance.initialize();
        instance.survey = surveySysId;
        instance.table_name = 'sc_request';
        instance.document = req.sys_id;
        instance.user = req.requested_for;
        instance.state = 'ready';
        instance.insert();

        gs.info('Survey triggered successfully for PSRA request ' + req.number);

    } catch (e) {
        gs.error(' Error triggering survey: ' + e);
    }

})(current, previous);