Solved

Transfer field value from one screen to another screen

  • 19 June 2023
  • 6 replies
  • 210 views

Userlevel 4
Badge

Hi,

I have a custom description field sitting in the Projects screen that is replacing the original Description field. This is because I needed the field to support a larger amount of characters for reports and I wasn’t able to achieve the correct result with the original description field sinc the reports would grab the original length the Description field rather than the new length.

 

Back to the main issue, when invoices are generated, the Transaction Description is grabbing content from the original Description field, but I would like this to come from the new custom description field I created.

 

I have tried something like the below to achieve this, but I can’t seem to get it working. I am trying to match an invoice line from the grid with the relevant project task in the Projects screen so that I can transfer the the content from the custom field to the invoice field.

 

What would you recommend to achieve this? I should note that this customisation is be published against the Invoices screen as I want the description to be brought in when an invoice is opened.

 

You will notice I am trying to update the invoice’s description field with a test string. I am unable to see this text appear in the description field, so I was wondering if there was something specific I needed to do to get both screens connected.

 

Let me know if I can provide any further information.

 

Kind regards,

Andrew

namespace PX.Objects.AR
{
public class ARInvoiceEntry_Extension : PXGraphExtension<PX.Objects.AR.ARInvoiceEntry>
{
#region Event Handlers

protected void ARTran_TranDesc_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
{

var row = (ARTran)e.Row;

var selectRevenueBudget = new PXSelect<PMRevenueBudget,
Where<PMRevenueBudget.projectID, Equal<Current<ARInvoice.projectID>>,
And<PMRevenueBudget.projectTaskID, Equal<Required<PMRevenueBudget.projectTaskID>>,
And<PMRevenueBudget.type, Equal<GL.AccountType.income>>>>>(this.Base);

var selectInvoiceLine = new PXSelect<ARTran,
Where<ARTran.projectID, Equal<Current<ARInvoice.projectID>>,
And<ARTran.taskID, Equal<Required<ARTran.taskID>>>>>(this.Base);

foreach (ARTran line in selectInvoiceLine.Select(row.TaskID))
{
line.TranDesc = "This is a test";
selectInvoiceLine.Update(line);
}

}

#endregion
}
}

 

icon

Best answer by aaghaei 3 July 2023, 09:32

View original

6 replies

Userlevel 7
Badge +11

Hi @AndrewA 

To accommodate a larger number of characters in the description field, you can execute the script to modify the table and expand the DAC by adding the "descr" field with the desired length.

Sample code:

ALTER TABLE ARTRAN
ALTER COLUMN Decr NVARCHAR(500)

  
 #region TranDescr
       public abstract class tranDescr : PX.Data.BQL.BqlString.Field<tranDescr> { }
        protected String _TranDescr;
        [PXDBString(500, IsUnicode = true)]
        [PXUIField(DisplayName = "Description ")]
        [PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]        
        public  String TranDescr
        {
            get{    return this._TranDescr;}
            set{ this._TranDescr = value;}
        }
        #endregion

Additionally, you can write the necessary logic in the Field Updated event using appropriate BQL and assign the value to the "descr" field.

Sample code

protected virtual void ARTran_InventoryID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated baseEvent)
            {
                ARTran row = (ARTran)e.Row;

                // Sample BQL. Write proper BQL to get the descr as per your requirement

                PMRevenueBudget selectRevenueBudget = PXSelect<PMRevenueBudget, Where<PMRevenueBudget.projectID, Equal<Required<ARInvoice.projectID>>,
                                                     And<PMRevenueBudget.projectTaskID, Equal<Required<PMRevenueBudget.projectTaskID>>,
                                                     And<PMRevenueBudget.type, Equal<PX.Objects.GL.AccountType.income>>>>>.Select(Base, row.ProjectID, row.TaskID);

                row.TranDesc = selectRevenueBudget?.Description;

            }

Userlevel 4
Badge

Hi Jini,

Sorry for the delay in getting back to you. I realise now that the first part of your response, the SQL script, is what I needed to do in the first place to avoid the current issue I am having.

As mentioned in the beginning of my question, I had created a new custom description field to replace the original one. Now I want to revert back so that the original description field is the one being used.

Using SQL, is there a way I can copy the value of the custom field over to the original field Maybe something like below?

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

 

Userlevel 7
Badge +11

Hi @AndrewA 

You can first modify a single record using the below query,

UPDATE PMRevenuBudget
SET Description = UsrDescriptionExt
WHERE projectid='urprojectID' // Add more conditions if needed

Then remove the where condition and run the script, it will update for all records.

Userlevel 7
Badge +10

Hi @AndrewA,

 

By using the ARTran_RowSelected event, you can dynamically update the tranDesc field of the ARTran cache based on the selected row's task ID. This allows you to display the custom description from the related project task in the invoice line.

 

Hope, it helps.!

 

Regards,

Sweta

Userlevel 7
Badge +8

Hi @AndrewA 

You can first modify a single record using the below query,

UPDATE PMRevenuBudget
SET Description = UsrDescriptionExt
WHERE projectid='urprojectID' // Add more conditions if needed

Then remove the where condition and run the script, it will update for all records.

 

Please note in case you are running SQL script there are no such objects “PMRevenueBudget” or “PMCostBudget” in SQL. These two are projection DACs which are only valid inside the Business Logics / DACs context. The Actual table that needs to be updated is “PMBudget” and the field “Type” (“I” for Revenue and “E” for Cost) differentiates the Revenue from Cost. Also considering the “Description” field is a nullable string, then the reliable encapsulation for it in the WHERE statement will be using the ISNULL function. In addition, if you are using direct updates to the DB, ALWAYS make sure the CompanyID (you get it from your Tenants screen) is included in your query. Something like below and of course you can limit the range by adding more conditions.

UPDATE [PMBudget] 
SET [Description] = [UsrDescriptionExt]
WHERE [CompanyID] = YourTenantID
AND [Type] = 'I for Revenue or E for Expense'
AND ISNULL([Description], '') = ''
AND ISNULL([UsrDescriptionExt], '') <> '';

 

Userlevel 4
Badge

Thanks everyone for your responses! Forgot to update this issue but I managed to resolve it after running the SQL script as suggested by @jinin.

Also, as @aaghaei mentioned, I ran into the issue of the PMRevenueBudget table not existing, but remembered to try the PMBudget table which worked.

Thanks again for your help!

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