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
It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
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
It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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