Updating Reference Field through BR

vidhya_mouli
Giga Sage

I have this reference field in my table:

vidhya_mouli_0-1700889200476.png

 

 

And this my code in BR:

 

 

current.vulnerability.v3_vector_string = extractedVectorWords;

 

 

When I check gs.addInfoMessage("HELLO: " + current.vulnerability.v3_vector_string);, I can see the string value. But it is not visible in the field. What is the problem?

 

 

BR is after BR with current.update();

1 ACCEPTED SOLUTION

@vidhya_mouli Update the script as follows.

 

(function executeRule(current, previous /*null when async*/ ) {

    var si = current.u_parent_si.getRefRecord();
    var inputString = si.description;

    // Get the input string parameter
    var wordExtractor = new WordExtractor();
    var extractedInformation = wordExtractor.extractInformation(inputString);

    // Access the extracted information
    var extractedVectorWords = extractedInformation.extractedVectorWords;
    var extractedAssetWords = extractedInformation.extractedAssetWords;
    var extractedSeverityValue = extractedInformation.extractedSeverityValue;

	// gs.addInfoMessage("extractedVectorWords: " + extractedVectorWords);
	// gs.addInfoMessage("extractedAssetWords: " + extractedAssetWords);
	// gs.addInfoMessage("extractedSeverityValue: " + extractedSeverityValue);

	 //Update for Domain
	if (extractedAssetWords != "No match found") {
        current.dns = "/ " + extractedAssetWords;
    }

    //Update for Vector
    if (extractedAssetWords != "No match found") {
        var vulEntryGR = new GlideRecord('sn_vul_entry');
        vulEntryGR.addQuery('v3_vector_string', 'LIKE', '%' + extractedVectorWords + '%');
        vulEntryGR.query();

        // Check if any records match the condition
        if (vulEntryGR.next()) {
			current.vulnerability= vulEntryGR.getValue('sys_id'); //set vulnerability
			//gs.addInfoMessage('extractedVectorWords is present in v3_vector_string: ' + extractedVectorWords);
        }
    }

	gs.addInfoMessage("CURRENT VECTOR VALUE: " + current.vulnerability.v3_vector_string);
	
	if (extractedSeverityValue != 0) {
        current.vulnerability.normalized_severity = extractedSeverityValue;
    }

	gs.addInfoMessage("CURRENT SEVERITY VALUE: " + current.vulnerability.normalized_severity);

	//current.update();

})(current, previous);

 

If this is an Before BR the above script will work as it is, if this is an after BR you will have to use

current.setWorkflow(false);
current.update();

 

Additionally at the end of the script.

 

 

View solution in original post

6 REPLIES 6

@vidhya_mouli Update the script as follows.

 

(function executeRule(current, previous /*null when async*/ ) {

    var si = current.u_parent_si.getRefRecord();
    var inputString = si.description;

    // Get the input string parameter
    var wordExtractor = new WordExtractor();
    var extractedInformation = wordExtractor.extractInformation(inputString);

    // Access the extracted information
    var extractedVectorWords = extractedInformation.extractedVectorWords;
    var extractedAssetWords = extractedInformation.extractedAssetWords;
    var extractedSeverityValue = extractedInformation.extractedSeverityValue;

	// gs.addInfoMessage("extractedVectorWords: " + extractedVectorWords);
	// gs.addInfoMessage("extractedAssetWords: " + extractedAssetWords);
	// gs.addInfoMessage("extractedSeverityValue: " + extractedSeverityValue);

	 //Update for Domain
	if (extractedAssetWords != "No match found") {
        current.dns = "/ " + extractedAssetWords;
    }

    //Update for Vector
    if (extractedAssetWords != "No match found") {
        var vulEntryGR = new GlideRecord('sn_vul_entry');
        vulEntryGR.addQuery('v3_vector_string', 'LIKE', '%' + extractedVectorWords + '%');
        vulEntryGR.query();

        // Check if any records match the condition
        if (vulEntryGR.next()) {
			current.vulnerability= vulEntryGR.getValue('sys_id'); //set vulnerability
			//gs.addInfoMessage('extractedVectorWords is present in v3_vector_string: ' + extractedVectorWords);
        }
    }

	gs.addInfoMessage("CURRENT VECTOR VALUE: " + current.vulnerability.v3_vector_string);
	
	if (extractedSeverityValue != 0) {
        current.vulnerability.normalized_severity = extractedSeverityValue;
    }

	gs.addInfoMessage("CURRENT SEVERITY VALUE: " + current.vulnerability.normalized_severity);

	//current.update();

})(current, previous);

 

If this is an Before BR the above script will work as it is, if this is an after BR you will have to use

current.setWorkflow(false);
current.update();

 

Additionally at the end of the script.

 

 

Thank you. This works, but the issue is it also updates other fields (I have few more references from the same reference table). I don't want other fields to update.