Solved

Copy value from custom field to original DAC field

  • 21 June 2023
  • 5 replies
  • 46 views

Userlevel 4
Badge

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);

}

 

icon

Best answer by Django 22 June 2023, 04:35

View original

5 replies

Userlevel 7
Badge +17

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!

Userlevel 7
Badge +5

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.

 

Userlevel 7
Badge +5

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.

Userlevel 4
Badge

Hi Django,

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

Kind regards,

Andrew

Userlevel 4
Badge

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

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved