Author Topic: sdk update transactionlist  (Read 2309 times)

Offline carpio

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
sdk update transactionlist
« on: October 11, 2017, 03:17:16 PM »
Hello,

I know how to get the keys and values from a transactionlist but how can i update a specific value of a key in a section?
Tried the add and set method but without success.

Offline PeteHoyle

  • Full Member
  • ***
  • Posts: 126
  • Karma: 13
Re: sdk update transactionlist
« Reply #1 on: October 12, 2017, 07:22:14 AM »
Hi Carpio,

Try this code:

            [code]
            CfgTransactionQuery query = new CfgTransactionQuery();
            query.Name = "PeteTransactionList";
            CfgTransaction transaction = confService.RetrieveObject<CfgTransaction>(query);
            if (transaction.UserProperties.ContainsKey("MySection"))
            {
                KeyValueCollection section = transaction.UserProperties["MySection"] as KeyValueCollection;
                if (section.ContainsKey("MyName"))
                {
                    section["MyName"] = "NewValue1";
                    transaction.Save();
                }
            }[/code]

Offline carpio

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: sdk update transactionlist
« Reply #2 on: October 12, 2017, 08:26:14 AM »
Hi Peter,

I was trying it in a kind of complex way but your code looks so easy.
Much appreciated

Offline carpio

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: sdk update transactionlist
« Reply #3 on: October 13, 2017, 08:49:00 AM »
Hi Pete, can you explain how to add a new section, key and value?
If I try to add the keyvaluepair I get an error

[code]var transaction = func.transactionlist_get("test");
            KeyValueCollection kvc = new KeyValueCollection();
            kvc.Add("KEY", "VALUE");
            transaction.UserProperties.Add(kvc);
            transaction.Save();[/code]
       

I get Error:{"Validation error : [CFGObjectPackingError] "}

Offline carpio

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: sdk update transactionlist
« Reply #4 on: October 13, 2017, 10:22:54 AM »
I found my mistake

[code] var transaction = func.transactionlist_get("test");
            KeyValueCollection kvc = new KeyValueCollection();
            kvc.Add("KEY", "VALUE");
            transaction.UserProperties.Add("SECTION", kvc);
            transaction.Save();[/code]