Clarity PPM

Expand all | Collapse all

PPM using wsdl soap with .net to write to an object

  • 1.  PPM using wsdl soap with .net to write to an object

    Posted 01-16-2019 11:16 AM

    All,

     I'm trying to do a reference to wsdl using soap to write to an object (below example is projects). I tried looking at VB.NET SOAP Integration Sample for Ideas which was great. But if anyone else can provide examples as I'm not sure what to put in header and what values should go under it. Any help would be appreciated.

    public Boolean LoadExecution()
    {
    ppm_objects.AllObjectsService ds = new ppm_objects.AllObjectsService();
    ppm_objects.Login login = new ppm_objects.Login();
    ppm_objects.Auth auth = new ppm_objects.Auth();
    try
    {
    login.Username = Common.GetKeyValue("ppm_user");
    login.Password = Common.GetKeyValue("ppm_pwd");
    //login.TenantID=
    var sessionId = ds.Login(login);
    if (!String.IsNullOrEmpty(sessionId))
    {
    auth.SessionID = sessionId;
    ds.AuthValue = auth;
    }
    if (String.IsNullOrEmpty(sessionId))
    { //We didn't login for some reason
    return false;
    }
    //XmlTypeMapping myTypeMapping =new SoapReflectionImporter().ImportTypeMapping(typeof(DepartmentsService));
    //XmlSerializer mySerializer = new XmlSerializer(myTypeMapping);
    XmlDocument request = new XmlDocument();
    request.LoadXml(@"<NikuDataBus xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
    xsi:noNamespaceSchemaLocation=""../xsd/nikuxog_department.xsd"">
    <Header action=""write"" externalSource=""NIKU"" objectType=""department"" version=""8.0""/>
    <Department>
    <Department entity=""temp"">
    <Departments>
    <ColumnValue name=""partition_code"">NIKU.ROOT</ColumnValue>
    </Departments>
    <Description>
    <ColumnValue name=""partition_code"">NIKU.ROOT</ColumnValue>
    </Description>
    <LocationAssociations>
    <ColumnValue name=""partition_code"">NIKU.ROOT</ColumnValue>
    </LocationAssociations>
    <Budget>
    <ColumnValue name=""partition_code"">NIKU.ROOT</ColumnValue>
    </Budget>
    <Child Department>
    <ColumnValue name=""partition_code"">NIKU.ROOT</ColumnValue>
    </Child Department>
    </Idea>
    </Department>
    </NikuDataBus>");
    //ds.WriteDepartment()

    try

    {

    ds.Logout(sessionId);

    }

    catch (ProtocolException)

    {

    // ignore throw;

    }

    }
    catch (Exception ex)

    {

    Common.WriteLog(String.Format("{0:MM/dd/yyyy HH:mm:ss}", DateTime.Now), Common.GetKeyValue("logpath"));
    Common.WriteLog(ex.ToString(), Common.GetKeyValue("logpath"));

    }


    return true;
    }



  • 2.  Re: PPM using wsdl soap with .net to write to an object

    Posted 01-25-2019 03:07 PM

    What I do is create a class with some helper methods for each object I need to insert.

     

    public static NikuDataBus NewNikuBus(String objectCode)
    {
         var xog = new NikuDataBus
         {
              Header = new Header
              {
                   externalSource = "NIKU",
                   version = "13.1.0.0248",
              },
              customObjectInstances = new List<CustomObjectInstancesType>
                                  {
                                       new CustomObjectInstancesType {objectCode = objectCode}
                                  }
         };
         return xog;
    }
    private static InstanceType NewStrip(String userName, String name, String desc, Int32 processing)
    {
         var strip = new InstanceType
         {
              instanceCode = "-1",
              parentInstanceCode = "-1",
              objectCode = "action_sub",
              parentObjectCode = "financialtask"
         };
         strip.OBSAssocs.complete = false;
         var security = new UserSecurityType
              {
                   rightCode = "odf_cst_action_sub_edit",
                   userName = userName
              };
         strip.Security.UserSecurity.Add(security);


         strip.CustomInformation.ColumnValue.Add(CaHelper.BuildCustomValue("desc_long", desc));
         strip.CustomInformation.ColumnValue.Add(CaHelper.BuildCustomValue("code", "-1"));

         if (processing == 1) name = String.Format("{0} - I", name);
         if (processing == 2) name = String.Format("{0} - II", name);
         if (processing == 3) name = String.Format("{0} - III", name);
         if (processing == 4) name = String.Format("{0} - IV", name);
         name = CheckStringLenght(name, 80);
         strip.CustomInformation.ColumnValue.Add(CaHelper.BuildCustomValue("name", name));

         return strip;
    }
    public static CustomInformationColumnValue BuildCustomValue(String name, String value)
    {
         return new CustomInformationColumnValue
         {
              name = name,
              Value = value //new List<string> { value }
         };
    }

     

    I then a insert method which takes the populated object and then I just serialize the object to xml and past that to WriteCustomObjectInstance soap method.

     

    public Boolean InsertNewStripObject(InstanceType instanceType, Checkbook_SpisLookupQueryRecord spisLookupRecord)
    {

              var name = instanceType.CustomInformation.ColumnValue.Find(x => x.name.IsEqualTo("name", true));
              var amount = instanceType.CustomInformation.ColumnValue.Find(x => x.name.IsEqualTo("amount", true));
              if (!Commit)
              {
                   NLogger.Info("Commit false=>Would have created: Strip {0} with Amount = {1}", name.Value, amount.Value);
                   return false;
              }

         var xog = NewNikuBus(instanceType.objectCode);
         try
         {
              var stripObject = QueryStripCode(instanceType, spisLookupRecord);
              if (stripObject == null)
              {
                   xog.Header.args = new List<args> { new args { name = "overrideAutoNumbering", value = "false" } };
              }
              else
              {
                   instanceType.instanceCode = stripObject.code;
                   var code = instanceType.CustomInformation.ColumnValue.Find(x => x.name.IsEqualTo("code", true));
                   if (code != null) code.Value = stripObject.code;
              }
              xog.customObjectInstances[0].instance.Add(instanceType);
              xog.XOGOutput = null;

              var xogString = xog.SerializeObject();
              var writeCustomObject = GetElement(xogString);
              var responseElement = ObjectsService.WriteCustomObjectInstance(writeCustomObject);
              var responseCustom = GetCustomInstanceResponse(responseElement);
              if (responseCustom.Statistics.failureRecords != 0)
              {
                   NLogger.Error(responseElement.OuterXml);
                   return false;
              }

              if (stripObject != null)
              {
                   NLogger.Info("Updated: Strip {0} with {1} on row {2}", name.Value, String.Format("Amount = {0} with code = {1}", amount.Value, stripObject.code), SheetRow);
                   return true;
              }

              stripObject = QueryStripCode(instanceType, spisLookupRecord);
              NLogger.Info("Created: Strip {0} with {1} on row {2}", name.Value, String.Format("Amount = {0} with code = {1}", amount.Value, stripObject.code), SheetRow);
              return true;
         }
         catch (Exception ex)
         {
              NLogger.Error(ex.Message);
              CaLogout();
              throw;
         }
    }

     

    V/r,

    Gene