Diosymar Gonzalez
Diosymar Gonzalez

Reputation: 9

Is there a way to call reusable rules in javascript block as the following: testRigor.execute("my reusable rule with 'param1'")?

Trying to achieve the following but it ends up just blocking the server and never finishing the execution even when cancelling the test run:

    execute JavaScript text starting from next line and ending with [END]
        var tenantName = "Ford CSP";
        testRigor.execute('map tenant name "' + tenantName + '" to vinDecoder domain');
    [END]

To execute a resuable rule in a javaScript block.

Here is the unedited full reusable rule:

execute JavaScript text starting from next line and ending with [END]

var vinSeed = testRigor.getStoredValue('vinSeed');
var tenantName = testRigor.getStoredValue('tenantName');
await testRigor.execute('map tenant name "' + tenantName + '" to vinDecoder domain');
var vinDecoderDomain = testRigor.getStoredValue('vinDecoderDomain');
var i = 0;
var newModifiedVin = '';
var vinDecoderResponse = '';
var modelReturnedByVinDecoder = '';
var customerOriginValueFromRequestSession = '';
var mileageValueFromRequestSession = '';



while(i < 10){

    testRigor.execute('modify VIN "' + vinSeed + '" and return modified VIN as variable "newModifiedVin"');
    newModifiedVin = testRigor.getStoredValue('newModifiedVin');
    testRigor.execute('validate vin "' + newModifiedVin + '" for vin type "'+ vinDecoderDomain +'" on vin decoder');
    vinDecoderResponse = testRigor.getStoredValue("vinDecoderResponse");
    testRigor.execute('parse Json string "' + vinDecoderResponse + '" with the JsonPath "$.data.model" and save the result as "modelReturnedByVinDecoder"');
    modelReturnedByVinDecoder = testRigor.getStoredValue('modelReturnedByVinDecoder');

    if(modelReturnedByVinDecoder !== 'null'){
    
         testRigor.execute('request session endpoint call by request type "vin" with request data "'+ newModifiedVin +'" for tenant "'+ tenantName +'"');
         testRigor.execute('parse Json string "' + requestSessionResponse + '" with the JsonPath "$.data.customerOrigin" and save the result as "customerOriginValueFromRequestSession"');
         testRigor.execute('parse Json string "' + requestSessionResponse + '" with the JsonPath "$.data.vehicleInformation.mileage" and save the result as "mileageValueFromRequestSession"');
         customerOriginValueFromRequestSession = testRigor.getStoredValue("customerOriginValueFromRequestSession");
         mileageValueFromRequestSession = testRigor.getStoredValue("mileageValueFromRequestSession");
         
         if(customerOriginValueFromRequestSession === "Unknown" && mileageValueFromRequestSession === "0"){
             testRigor.putStoredValue('vin', newModifiedVin);
             break;
         }
    }
    vinSeed = newModifiedVin;
    i++;
}

[END]

Upvotes: 0

Views: 46

Answers (1)

Zeros-N-Ones
Zeros-N-Ones

Reputation: 1082

There may be a couple of issues causing the infinite execution that causes the hanging issue:

  • If the JavaScript block is trying to execute a rule that itself contains JavaScript that calls the same rule, it could create an infinite loop

  • The execute() command might need to be handled asynchronously

I suggest you try these approaches:

// Option 1: Use async/await
execute JavaScript text starting from next line and ending with [END]
    var tenantName = "Ford CSP";
    await testRigor.execute('map tenant name "' + tenantName + '" to vinDecoder domain');
[END]

// Option 2: Use a callback
execute JavaScript text starting from next line and ending with [END]
    var tenantName = "Ford CSP";
    testRigor.execute('map tenant name "' + tenantName + '" to vinDecoder domain', function(result) {
        // Handle the result here
        console.log('Rule execution completed');
    });
[END]

Do you mind sharing what’s inside the reusable rule you’re trying to execute?

And are you seeing any specific error massages in the logs?

Upvotes: 0

Related Questions