Question
· Dec 2, 2020

Update object from XML

Hi guys,

I have this method to create object from XML

ClassMethod XMLNew(doc As %XML.Document, node As %Integer, contOref As %RegisteredObject = "") As TruLaser.ProductionPackage
{
    Set id=""     Set tmpnode=doc.GetNode(node)
    Do tmpnode.MoveToFirstChild()
    Do {
        //compare data node to the string given by the NAMEOFEXPORTID parameter
        //which indicates the XMLNAME of the ids for this object
        If tmpnode.NodeData=..#NAMEOFEXPORTID {
            //get the text from this node; this corresponds to an id in the database
            Do tmpnode.GetText(.id)}
        While tmpnode.MoveToNextSibling()
    
    &SQL(SELECT ID INTO :id FROM TruLaser.ProductionPackage WHERE Barcode = :id )   
    
    SET:SQLCODE=100 id=""      //if there is no id in the given node, create a new object
    IF (id="")
    {
        Write !, "Creating a new object..."
        Quit ..%New()
    }
    
    //open the given object
    Set result=..%OpenId(id)     //if the id doesn't correspond to an existing object, create a new object
    IF (result=$$$NULLOREF)
    {
        Write !, "Creating a new object..." 
        Quit ..%New()
    }

         Quit result
}

My problem is updating of existing object. It does update  but only Properties. Where is defined relationship, this is not update but created always new record. I dont want duplicate records. 

What is the way to clear all relationship for that object and insert new relationships during the update?

 

Product version: Caché 2018.1
Discussion (1)1
Log in or sign up to continue