1. Tony Fahlberg
  2. Beta Testing
  3. Friday, 21 February 2020 16:59 PM UTC

Hi - Is it possible to dynamically update the expression in a computed column (DwCompute) and then call the IDataStore<TModel> or IDataStore GetItem method on the column to have it return the new expressions value? 

If so, could you provide an example / pseudo code on how to accomplish this.    - Thank you

Accepted Answer
Govinda Lopez @Appeon Accepted Answer Pending Moderation
  1. Friday, 21 February 2020 22:42 PM UTC
  2. Beta Testing
  3. # Permalink

Hi Tony,

 

You can use the IExpressionable object to do this. So, you would actually need to be using the [DwCompute()] attribute on the .NET DataStore Model. Then, the Expression property of the DwMeta.Computes object has a GET and a SET to it. So you can make the changes this way.

 

Following is an example of obtaining the expression from a .NET DataStore computed field:

 

string exp = ds_Customers.DwMeta.Computes.FirstOrDefault().Expression.Expression;

 

And, next is an example of setting the expression to the .NET DataStore computed field:

 

ds_Customers.DwMeta.Compute.FirstOrDefault().Expression.Expression = "city + ', ' + state";

 

 

Please do keep in mind, however, that since this is a beta version, there are some known issues with the DwCompute Attribute of the .NET DataStore Model (more details here).

 

I hope this helps.

Regards,

Comment
  1. Logan Liu @Appeon
  2. Saturday, 22 February 2020 16:23 PM UTC
And one more thing. When using the "PowerScript.Bridge" package (mainly designed for PowerScript Migrator feature), we can also call the extended DataStore.Modify(String) method to modify the calculation expression.

It works similar to the original way in PB.

E.g. :

DataStore ds = new DataStore("d_dept", _context);

ds.Modify("Compute_1.Expression = 'getrow()'");
  1. Helpful
  1. Armeen Mazda @Appeon
  2. Saturday, 22 February 2020 17:55 PM UTC
Hi Tony, Adding to what Logan said, if you prefer to write your code the way he outlined instead of the suggestion by Govinda, then you need to be on a "CloudPro" subscription level of PowerBuilder since the PowerScript.Bridge library is part of that. If you can go with the way Govinda outlined, then all you need is the "Professional" subscription level of PowerBuilder.
  1. Helpful
There are no comments made yet.
Tony Fahlberg Accepted Answer Pending Moderation
  1. Saturday, 22 February 2020 00:28 AM UTC
  2. Beta Testing
  3. # 1

Awesome!  Thank you.

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.