get item instance(context item) on before add

オフライン

hello

I'm developping a method that is going to be trigered by a server event on before Add/update .The method needs to retrieve the inputs entered by the user creating the item.

problem is when i was first testing this method. I tested it with an already created object that i got by keyed name but in reality the item is not yet created and i need to retrieve the instance of the object in my method to be able to execute my logic.

i've tried this :

Item template =  inn.getItemById("ZFCcontrainteTemplate", this.getID());

but got this error:

Object reference not set to an instance of an object.

the method is c# server side

obviously i feel like the this.getID is not suficent to point to the instance of the item being created but i have really no idea where to look for that so if you have any information that might help me it would be much apreciated.

thanks

lucas

  • Can you share your method ? Ideally on before Add, you can get the this.getID()

  • 0 オフライン in reply to Gopikrishnan

    here is my code:

    System.Diagnostics.Debugger.Log(0,"message", "checking values ...");
    
    Innovator inn = this.getInnovator();
    
    Item FCitemType = inn.newItem("itemtype", "get");
        FCitemType.setProperty("name","ZFCcontrainteTemplate");
        // FCitemType.setAttribute("select", "name");
        // FCitemType.setAttribute("where", "[ZFCcontrainteTemplate].name like 'testTemplate'");                     //first i get all props of my item type starting with z
        
        
        Item relproperty = FCitemType.createRelationship("property", "get");
        
        relproperty.setAttribute("select", "name");
        // property.setPropertyCondition("label", "like");
        // property.setProperty("label", "z%");
        relproperty.setAttribute("where", "[Property].name like 'z%'");
        // console.log("ttoot");
        
        // console.log("FCitemType before apply: "+FCitemType.ToString());
        System.Diagnostics.Debugger.Log(0,"message", "\nFCitemType before apply: "+FCitemType.ToString());
        
        FCitemType = FCitemType.apply();
        if(FCitemType.isError())
        {
            // console.log("FCitemType error:"+FCitemType.getErrorDetail());
            return inn.newError(FCitemType.getErrorDetail());
        }
        
        System.Diagnostics.Debugger.Log(0,"message", "\nitem Count: "+FCitemType.getItemCount());
        // console.log("item Count: "+FCitemType.getItemCount());
        
        Item FCrelItemTypeMyprops = FCitemType.getItemsByXPath("//Item[@type='Property']");
        
        if(FCrelItemTypeMyprops.isError())
        {
            // console.log("FCitemType error:"+FCrelItemTypeMyprops.getErrorDetail());
            return inn.newError(FCrelItemTypeMyprops.getErrorDetail());
        }
        
        System.Diagnostics.Debugger.Log(0,"message", "\nrelitem Count: "+FCrelItemTypeMyprops.getItemCount());
        // console.log("relitem Count: "+FCrelItemTypeMyprops.getItemCount());
        
        for(int i=0; i<FCrelItemTypeMyprops.getItemCount();i+=3)
        {
            Item template =  inn.getItemById("ZFCcontrainteTemplate", this.getID());                                   //and then i want to check properties two by two 
            
            Item FCprop1=FCrelItemTypeMyprops.getItemByIndex(i+1);
            string varFiltrPropName= FCprop1.getProperty("name");
            string isEmpt1 =template.getProperty(varFiltrPropName);
            
            // if (isEmpt1==null)
            // {isEmpt1="is null";}
            System.Diagnostics.Debugger.Log(0,"message","\n"+ varFiltrPropName + " = "+ isEmpt1);
            // console.log(FCprop1.getProperty("name") + " = "+ isEmpt1);
            
            Item FCprop2=FCrelItemTypeMyprops.getItemByIndex(i+2);
            string isEmpt2 =template.getProperty(FCprop2.getProperty("name"));
            string operatorPropName= FCprop2.getProperty("name");
            // if (isEmpt2==null)
            // {isEmpt2="is null";}
            
            System.Diagnostics.Debugger.Log(0,"message","\n"+ operatorPropName + " = "+ isEmpt2);
            // console.log(FCprop2.getProperty("name") + " = "+ isEmpt2);
            string[] FCprop1tab = varFiltrPropName.Split('_');
            string[] FCprop2tab = operatorPropName.Split('_');
    
            if(FCprop1tab[0]==FCprop2tab[0] && FCprop1tab[1]==FCprop2tab[1]) // checking that it compares the right props
            {
                if ((isEmpt1 == null && isEmpt2 != null)||(isEmpt2 == null && isEmpt1 != null ) )       // i need the two properties to be in same state (if one is undefined/null the other one should be too)
                {
                    System.Diagnostics.Debugger.Log(0,"message", "\nerreur au niveau de la valeur de filtrage et de l'operateur de la propriete "+FCprop1tab[1]+" pour les "+FCprop2tab[0].Substring(1)+ ".\nSi une valeur de filtrage est definie son operateur doit l'etre aussi");
                    return inn.newError("erreur au niveau de la valeur de filtrage et de l'operateur de la propriete "+FCprop1tab[1]+" pour les "+FCprop2tab[0].Substring(1)+ ".\nSi une valeur de filtrage est definie son operateur doit l'etre aussi.");
                }
            }
            else
            {
                                System.Diagnostics.Debugger.Log(0,"message", "erreur decallage dans les props");
                                return inn.newError("erreur decallage dans les props");
    
            }
            // console.log return inn.newError  alert
            
        
        }
        return this;
        System.Diagnostics.Debugger.Break();

  • 0 オフライン in reply to Gopikrishnan

    hello,

    so the "this.getID()" actually gets an id 

    but this id is not from an object of my itemtype ZFCcontrainteTemplate

    Item template =  inn.getItemById("ZFCcontrainteTemplate", this.getID()); 

    i think thats why no item is retrieved from the get item by ID 

    let me know if this makes sense or if u have a better explanation.

    (and i run the method on after add of a ZFCcontrainteTemplate item.)

    thanks,

    Lucas