I'm currently writing a post request witha a JSON body. i'm wanting my JSON to produce unique data on each iteration of test plan, but due to dependancies, this is leading to my requests sending invalid data.
for example, one of the parameters is DocumentID. I have written a ${chooseRandom()} function to select the documentID:
${__chooseRandom("5ea1a4116f1987335809ae0d","5ea1a4d36f1987335809ae0e","5ea29645f5082539f8d430cd","5ea29f6df5082539f8d430db","5ea29fa4f5082539f8d430dc",companyDocumentID)}
so the selected value is stored in the variable "companyDocumentID".
the next parameter is ReferenceFieldValue. this is an id that is associated to the companyDocumentID, and based on the selection of companyDocumentID in the prior chooseRandom function, the referenceFieldValue needs to match the correct ID.
for example, if the first choose random option is selected, then ReferenceFieldValue needs to be "1", if the second choose random option is selected, then ReferenceFieldValue needs to be "2" and so on for all 5 options.
i have tried to use an if function to capture the correct ReferenceFieldValue, but as the false value, i have nested a further if statement:
${__if(${companyDocumentID}, "5ea1a4116f1987335809ae0d", "1", ${__if(${companyDocumentID}, "5ea1a4d36f1987335809ae0e", "2", ${__if(${companyDocumentID}, "5ea29645f5082539f8d430cd", "3", ${__if(${companyDocumentID}, "5ea29f6df5082539f8d430db", "4", ${__if(${companyDocumentID}, "5ea29fa4f5082539f8d430dc", "5", "6")})})})})}
but when i test my request, ReferenceFieldValue is returning as "6", meaning companyDocumentID is not equal to any of the possible values, which isn't the case, so i'm confused as to why this is happening.
I have three questions from this:
- why is ReferenceFieldValue returning "6", when i have covered all of the possible values of companyDocumentID?
- is there an easier way to achieve my desired outcome?
- can you nest if functions to act as an else/elseif?
here is the fulle JSOn body to help give context:
{
"projectId": "${projectID}",
"classId": "${classID}",
"data": {
"90e7a6df-3c47-3f09-61cd-d37720e5103a": {
"documentId": ${__chooseRandom("5ea1a4116f1987335809ae0d","5ea1a4d36f1987335809ae0e","5ea29645f5082539f8d430cd","5ea29f6df5082539f8d430db","5ea29fa4f5082539f8d430dc",companyDocumentID)},
"referenceFieldValue": ${__if(${companyDocumentID}, "5ea1a4116f1987335809ae0d", "1", ${__if(${companyDocumentID}, "5ea1a4d36f1987335809ae0e", "2", ${__if(${companyDocumentID}, "5ea29645f5082539f8d430cd", "3", ${__if(${companyDocumentID}, "5ea29f6df5082539f8d430db", "4", ${__if(${companyDocumentID}, "5ea29fa4f5082539f8d430dc", "5", "6")})})})})}
},
"fc06d039-b3e8-988a-5402-88666acd10e5": "${__UUID()}",
"fffef986-9c12-8ca4-2d22-3a7e8abd08f7": "${__UUID()}",
"44b9a8e0-d933-047c-8659-cb4f1672cddc": "${__UUID()}@example.com"
}
}