I have a script that scans every item laptop in my Snipe IT inventory, compares it against that same instance in my Jamf Pro server, and for any fields that do not match, it creates an XML and sends that XML over to Jamf. What I need is for the XML to have all of its elements "wiped" after sending the payload over. I have tried countless --- countless --- ways to make this happen, but even when I "print" the supposedly "wiped" payload at the end of the script and confirm that the element was removed, it still appears the next time around when I inspect the payload that was sent to Jamf. If I have three laptops with info that gets sent over, I get three fields. Four, I get four. And so on. I really need to figure out how to reset this XML to make this script cleaner.
Here is where I am creating the XML, if the information does not match.
// let's compare the DEVICE ASSIGNMENT across our two systems, knowing that itassets is our SOT
if ($jamf_assignment !== $itassets_assignment) {
echo "
" . "ALERT: The device assignment is not in sync across our systems!" . "
";
if (!isset($location)) {
$location = $jamf_xml->createElement('location');
$location->appendChild($jamf_xml->createElement('real_name',$itassets_assignment));
$process_xml = 1;
} else {
$location->appendChild($jamf_xml->createElement('real_name',$itassets_assignment));
$process_xml = 1;
}
} else {
echo "
" . "DEVICE ASSIGNMENT CHECKS OUT! ALL GOOD HERE!" . "
";
}
And here is where I am turning it into a payload, about to be sent.
if (!empty($location)) {
$computer->appendChild($location);
}
$jamf_xml->appendChild($computer);
$jamf_payload = $jamf_xml->saveXML();
And finally here is where I am trying to reset that XML, and start fresh with the next loop.
// and finally let's destroy the XML file
if (!empty($general)) {
$computer->removeChild($general);
}
if (!empty($location)) {
$computer->removeChild($location);
}
$jamf_xml->appendChild($computer);
$jamf_payload = $jamf_xml->saveXML();