Picture of Wim 4127
Registered 6 years 112 days
Wim 4127 Wednesday, 13 July 2022, 01:46 PM
How to use ConfigContext::WriteItemValue
Hi,

I have a configuration parameter that I declare at startups as myconfigstring = new ConfigString(ctx, "name", "", true, false); This is by default empty and that is good. It is unmanaged since I want to update it from within the C++ code as well, and, SetValue can only be used in case it is an unmanaged key.

At a certain point I want to change the value.
I do this by calling myconfigstring->SetValue(newvalue.c_str()); but this doesn't change the database (I think? Please conform/deny).

From the documentation, I think I understand that I have to use the ConfigContext::WriteItemValue then.
So I call ctx->WriteItemvalue(myconfigstring, newvalue.c_str(), false);
However, this doesn't store the configuration value, because after the restart of my application the configuration key is again empty.

Then I see that the writeitemvalue function returns a task and i do
ITask* task = ctx->WriteItemvalue(myconfigstring, newvalue.c_str(), false);
task->Start();
But, also this doesn't work because after restart of my app, the value is again empty and not the value that I stored.

I run the app from the debugger. I'm sure the newvalue string is not empty.

Please provide some more details on how to save the value of the configuration parameter from within the C++ application.
Andreas Fink
Moderator Registered 12 years 277 days
Andreas Fink (innovaphone) Tuesday, 26 July 2022, 01:23 PM
Re: How to use ConfigContext::WriteItemValue
Hello Wim,

in case of unmanaged items the function UpdateUnmanagedItems of the ConfigContext should be used instead. It will return a task that should be handled as usual.

We will update the documentation regarding this functionality (for the time being it is missing):
https://sdk.innovaphone.com/13r3/sdk/common/lib/config.htm#ConfigContext

Best Regards
Andreas Fink
Picture of Sam 4951
Registered 4 years 228 days
Sam 4951 Wednesday, 10 August 2022, 03:03 PM
Re: How to use ConfigContext::WriteItemValue
Hey Andreas,

Thanks, it works with UpdateUnmanagedItems.

There's a little bug though: when you use the parameterless Start method of the ITask returned by UpdateUnmanagedItems, nothing happens.
You must use the Start method with the UTask* parameter.

Best regards,
Sam
Andreas Fink
Moderator Registered 12 years 277 days
Andreas Fink (innovaphone) Tuesday, 26 July 2022, 02:30 PM in response to Wim 4127
Re: How to use ConfigContext::WriteItemValue

> It is unmanaged since I want to update it from within the C++ code as well

And just to make sure - unmanaged items are not available from JsonApi, only from the app service.

So writing an unmanaged item from app service and from JsonApi is not possible.

Best Regards
Andreas Fink
Picture of Wim 4127
Registered 6 years 112 days
Wim 4127 Tuesday, 9 August 2022, 09:15 AM
Re: How to use ConfigContext::WriteItemValue
Hi Andreas,

isn't your statement a contradiction?

And just to make sure - unmanaged items are not available from JsonApi, only from the app service.
So writing an unmanaged item from app service and from JsonApi is not possible.

I only need to set and read the config string in my C++ code... what do I have to do. IMHO, it is an unmanaged item? Correct?
Picture of Wim 4127
Registered 6 years 112 days
Wim 4127 Tuesday, 9 August 2022, 09:22 AM
Re: How to use ConfigContext::WriteItemValue
Ok, Sam explained to me what you meant... you mean I cannot update in C++ and in json in the latter case... only in C++. misinterpreted your statement so you can ignore the remark
Andreas Fink
Moderator Registered 12 years 277 days
Andreas Fink (innovaphone) Tuesday, 9 August 2022, 09:24 AM in response to Wim 4127
Re: How to use ConfigContext::WriteItemValue
Hello Wim,

no, it is not in context of your post I'm referring to:

> It is unmanaged since I want to update it from within the C++ code as well

To write from App Service please use UpdateUnmanagedItems (see my previous post). This should fix your issue.

Best Regards
Andreas Fink


Picture of Wim 4127
Registered 6 years 112 days
Wim 4127 Wednesday, 7 September 2022, 08:52 AM
1 of 1 users consider this post helpful
Re: How to use ConfigContext::WriteItemValue
Ok, it is working. Most important thing is that when using these tasks, you also have to provide a UCallback parameter.

You can execute the tasks with or without the UCallback parameter and this will compile and even run perfectly, but it doesn't actually do something. It also doesn't log it doesn't do anything, which would have been nice, since not providing it is allowed by the interface. If it is allowed but not supported in that specific task, it should at least log that so that users are aware of it. If it is not allowed, do not foresee this in the interface then and make the callback parameter obligatory. And if not forced/reported in the code, then it might be good to explicitly mention this in the documentation that some tasks do or not do stuff depending on whether or not there is a UCallback provided.
← You can define your color theme preference here