Working to upgrade some MS-350s to MS-355 so can't use the clone function. I had this script working for awhile, but it seems something changed with how the voiceVlan field is handled. So the collection runs with 48 iterations, a Get and Put operation for each switch port.
When using Get to pull switchport settings (MS-350), the voiceVlan field is blank, but when it is Put to the replacement switch (MS-355), the word null is required without quotes.
I could assign null manually, but the problem is I don't want to overwrite the port configs where the voiceVlan value is not null. When a voice vlan is configured on the port, the script works fine. I need an If "blank" statement to assign the value of null, just don't know how to write that statement in JSON.
Any thoughts on how to modify the JSON test to change voiceVlan variable value from "" to "null"?
This runs in tests on Get request:
var jsonData = JSON.parse(responseBody);
number = jsonData.number;
console.log(number);
pm.environment.set("number", number);
name = jsonData.name;
console.log(name);
pm.environment.set("name", name);
tags = jsonData.tags;
console.log(tags);
pm.environment.set("tags", tags);
enabled = jsonData.enabled;
console.log(enabled);
pm.environment.set("enabled", enabled);
poeEnabled = jsonData.poeEnabled;
console.log(poeEnabled);
pm.environment.set("poeEnabled", poeEnabled);
type = jsonData.type;
console.log(type);
pm.environment.set("type", type);
vlan = jsonData.vlan;
console.log(vlan);
pm.environment.set("vlan", vlan);
voiceVlan = jsonData.voiceVlan;
console.log(voiceVlan);
pm.environment.set("voiceVlan", voiceVlan);
allowedVlans = jsonData.allowedVlans;
console.log(allowedVlans);
pm.environment.set("allowedVlans", allowedVlans);
isolationEnabled = jsonData.isolationEnabled;
console.log(isolationEnabled);
pm.environment.set("isolationEnabled", isolationEnabled);
rstpEnabled = jsonData.rstpEnabled;
console.log(rstpEnabled);
pm.environment.set("rstpEnabled", rstpEnabled);
stpGuard = jsonData.stpGuard;
console.log(stpGuard);
pm.environment.set("stpGuard", stpGuard);
accessPolicyNumber = jsonData.accessPolicyNumber;
console.log(accessPolicyNumber);
pm.environment.set("accessPolicyNumber", accessPolicyNumber);
linkNegotiation = jsonData.linkNegotiation;
console.log(linkNegotiation);
pm.environment.set("linkNegotiation", linkNegotiation);
This runs with Put request after the Get populates variable values
{
"number": {{number}},
"name": "{{name}}",
"tags": "{{tags}}",
"enabled": {{enabled}},
"poeEnabled": {{poeEnabled}},
"type": "{{type}}",
"vlan": {{vlan}},
"voiceVlan": {{voiceVlan}},
"allowedVlans": "{{allowedVlans}}",
"isolationEnabled": {{isolationEnabled}},
"rstpEnabled": {{rstpEnabled}},
"stpGuard": "{{stpGuard}}",
"accessPolicyNumber": "{{accessPolicyNumber}}",
"linkNegotiation": "{{linkNegotiation}}"
}