Skip to main content
Answer

Copy value from custom field to original DAC field

  • June 21, 2023
  • 5 replies
  • 89 views

Forum|alt.badge.img

Hi,

What would be the best way to reverse the code below so that I can update the original DAC field with the custom DAC field?

 

The reason for this reversal is that I created the new custom field to replace the original Description field. This is because I wanted the descripition field to hold 4000 characters, but reports would still be pulling it in as having only 250 characters since I didn’t update the SQL.

 

Now that I realise my mistake of not updating the length of the description field via SQL, I will need to reverse the code below so that I can move the text back into the original description field as this custom field is no longer needed.

 

Kind regards,

Andrew

 

protected void PMRevenueBudget_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{

PMRevenueBudget row = (PMRevenueBudget)e.Row;
if (row is null || row.Description is null || row.Description == "") return;

var value = row.Description;

cache.SetValueExt<PMBudgetExt.usrDescriptionExt>(row, value);
row.Description = "";

}



protected void PMRevenueBudget_UsrDescriptionExt_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
{

PMRevenueBudget row = (PMRevenueBudget)e.Row;
if (row is null || row.Description is null || row.Description == "") return;

if (row.Description is object)
cache.SetDefaultExt<PMBudgetExt.usrDescriptionExt>(row);

}

 

Best answer by Django

Hi Andrew,

Yes, that’s basically it. I would be tempted to write the assignment as:

SET Description = SUBSTRING(UsrDescriptionExt,1,lengthOfDescription)

just so that you’re only pulling in the first 50 characters (or however long the Description field is).

And then the WHERE clause as:

WHERE ((Description = '') OR (Description IS NULL)) AND (UsrDescriptionExt IS NOT NULL)

I think that the framework will convert empty strings to null values but there may be cases where it does not.

5 replies

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • June 21, 2023

Hi @AndrewA  In RowSelected and FieldSelecting events, we should not assign the values.

As you wanted to update the Original DAC field from Custom field.

You can write a field updated event for the Custom field, and assign the custom field value to the original field.

 

hope this helps!


Forum|alt.badge.img+7
  • Captain II
  • June 21, 2023

Is this a one time operation that you need to perform on your database?  If so, you can write a SQL script in a separate customization project that will be run when you publish it. Then you can unpublish it and delete the customization project.

 


Forum|alt.badge.img
  • Author
  • Varsity I
  • June 21, 2023

Hi Naveen and Django,

Thank you both for your responses! Yes this will be a one time operation. How would the SQL look if I want to copy text from the custom field to the original field? Would it be something like the below?

 

I only want to reverse the records where the custom field has been used instead of the original field:

 

UPDATE PMRevenueBudget
SET Description = UsrDescriptionExt
WHERE Description = '' and UsrDescriptionExt <> ''

 

Kind regards,

Andrew


Forum|alt.badge.img+7
  • Captain II
  • Answer
  • June 22, 2023

Hi Andrew,

Yes, that’s basically it. I would be tempted to write the assignment as:

SET Description = SUBSTRING(UsrDescriptionExt,1,lengthOfDescription)

just so that you’re only pulling in the first 50 characters (or however long the Description field is).

And then the WHERE clause as:

WHERE ((Description = '') OR (Description IS NULL)) AND (UsrDescriptionExt IS NOT NULL)

I think that the framework will convert empty strings to null values but there may be cases where it does not.


Forum|alt.badge.img
  • Author
  • Varsity I
  • June 22, 2023

Hi Django,

I will update the SQL with those changes. Thanks so much for your help!

Kind regards,

Andrew