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

Sandeep Rajput
Tera Patron
Tera Patron

@vidhya_mouli Could you please replace current.vulnerability.v3_vector_string = extractedVectorWords; with the following lines in your business rule and check if the value on the v3_vector_string field gets populated.

//current.vulnerability.v3_vector_string = extractedVectorWords;
var vulnerabilityRef = current.vulnerability.getRefRecord();
vulnerabilityRef.v3_vector_string = extractedVectorWords;
vulnerabilityRef.update();

Hope this helps.

I am not looking at updating the reference table record. I want to update the current table reference field. 

 

I tried this code and it was throwing error.

@vidhya_mouli If I am not wrong v3_vector_string is a field on sn_vul_entry table and you are trying to set the value extractedVectorWords on this field using the following line. 

 

current.vulnerability.v3_vector_string = extractedVectorWords;

 

Also, could you please share the error you are getting? If possible, please share the business rule script.

This my BR:

 

 

(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.v3_vector_string = extractedVectorWords;
			//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);

 

 

 

I am checking if "extractedVectorWords" is present in the table "sn_vul_entry", then I update this value in the current table. sn_vul_entry will have many record with this value. Even when 1 record is present, I want to update. The current table is "sn_vul_vulnerable_item"