BookmarkSubscribeRSS Feed
nrose
Quartz | Level 8
Hi,

I am designing a custom task that sets the fmtsearch option by clicking on radio buttons. The custom task does not persist, i.e. you open it, set your option, run it and the task disappears. What I want to be able to do is store the current choice so that when the user opens up the task again, it remembers during the session what the current choice is.

Is there a way to serialize this information so it can be used for the duration of a SAS EG session?

Any advice appreciated.

Nick
4 REPLIES 4
ChrisHemedinger
Community Manager
Yes. Serializing the state of the task requires that you implement the XmlState property (get and set). Or, if you are using the SAS.Tasks.Toolkit and inheriting from the SasTask class, override the RestoreStateFromXml and GetXmlState methods.

Most of the examples at:
http://support.sas.com/documentation/onlinedoc/guide/customtasks/index.htm

show this technique. Note that I added several examples in the past couple of months, in case you haven't checked there lately.

Look at the Calculate Lag example or System Command example.

Chris
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
nrose
Quartz | Level 8
Thanks Chris,

The problem is that I dont quite get how these get and set methods work. The methods return or deserialize a string, but does this string need to be stored somewhere? Remember, my custom task's show method returns a 'Canceled' ShowResult value, and therefore does not store a result. I have tried to implement what is demonstrated in the examples into my custom task, but it doesnt seem to work. What might I be doing wrong?

I have had to resort to serialize the properties into an xml file, but your examples don't seem to require this. An explanation, or a reference to somewhere which explains how these methods are handled would be helpful. Is there something being done behind the scenes with these methods that might help me figure it out?

Thanks,

Nick
ChrisHemedinger
Community Manager
Nick, sorry for the delay in getting back.

If your task returns Cancel as a result, then the state is *not* stored in the EG project. You might have realized that by now.

So, then you are on your own for serializing the state elsewhere, if the state is not project specific. You can use .NET methods to read/write a file of your own design into a safe location, such as somewhere in %appdata% where the user is sure to have write access.

Chris
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
nrose
Quartz | Level 8
Thanks Chris,

I have done exactly that - serialized to an XML in Windows/temp. Just wanted to make sure there was no inbuilt method.

Nick

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1492 views
  • 0 likes
  • 2 in conversation