Skip to main content
Solved

How to add a file upload button in the custom screen in Modern UI

  • January 27, 2025
  • 1 reply
  • 98 views

Forum|alt.badge.img

Hello Everyone, 

I am trying to add a file upload button in the Modern UI screen. 

I have a Button called browse button in custom screen, when I click on the button a pop will appear and in the popup we will have “Choose File” button to upload the files. The file upload button is not working for me on button click in Modern UI as it worked in Classic UI Below is the the image of the screen for reference.

 

Below is my ts and html code

import { Messages as SysMessages } from "client-controls/services/messages";
import { createCollection, 
	createSingle, 
	PXScreen, 
	graphInfo, 
	PXActionState, 
	viewInfo,  } from "client-controls";
import { KNCFBulkBatchSyncFilter, KNCFItemCategory, KNCFAttributeGridSyncFilter, KNCFBulkProductDetails } from "./views";

@graphInfo({
	graphType: "KNCFCore.KNCFBatchProductSyncProcess", 
	primaryView: "Filter", 
})
export class KNCF5141 extends PXScreen {
	LoadRecords: PXActionState;
	ResetFilter: PXActionState;
	browse: PXActionState;

   	@viewInfo({containerName: "Selection"})
	Filter = createSingle(KNCFBulkBatchSyncFilter);
   	@viewInfo({containerName: "Sales Categories"})
	Category = createCollection(KNCFItemCategory);
   	@viewInfo({containerName: "Attributes"})
	AttributeFilter = createCollection(KNCFAttributeGridSyncFilter);
	BulkProductSync = createCollection(KNCFBulkProductDetails);
}
<template>

	<qp-template id="form0" name="1-1"> 
		<div class="v-stack" id="Filter_PXLayoutRule11_vStack" wg-container slot="A">

			<qp-template id="pnldateRange0" name="1"> 
				<qp-fieldset id="pnldateRange0" wg-container view.bind="Filter" slot="A" >
					<field name="ConnectorID" ></field>
					<field name="SyncData" ></field>
					<field name="FilterByDate" ></field>
					<field name="FromDate">
						<qp-field slot="label" control-state.bind="Filter.ToDate"></qp-field>
					</field>
				</qp-fieldset>
			</qp-template> 
				<div class="v-stack" id="PXPanel2_vStack" wg-container slot="A">
				  	<qp-template id="PXPanelContent" name="1">
						<qp-fieldset id="PXPanelContent" wg-container view.bind="Filter" slot="A">
						  	<field name="FilterBySpecificSKU"></field>

						  	<qp-label id="PXEmptySpace"></qp-label>
						  	<qp-label id="edlabel" caption="Or"></qp-label>
						  	<field name="SKUFilter">
								<qp-textarea id="edSKUFilter" rows="4" style="width: 200px; height: 60px;"></qp-textarea>
						  	</field>
						</qp-fieldset>
						<qp-button id="buttonBrowse" state.bind="browse"  PopupPanel="UploadPackagePanel"></qp-button>
						<qp-upload-dialog
							id="UploadPackageDlg"
							key="UploadPackagePanel"
							session-key="KNCFBatchProductSyncProcess_UploadPackage"
							caption="Open Package"
							allowed-types=".xlsx">
						</qp-upload-dialog>

				  	</qp-template>
				  	<qp-label
						id="PXLabel1"
						caption="Please upload an Excel file with the first column containing the entity Id's and first row containing header as 'InventoryID'.">
				  	</qp-label>
				</div>
			<qp-button id="buttonLoadRecords" state.bind="LoadRecords" ></qp-button>
			<qp-button id="buttonResetFilter" state.bind="ResetFilter" ></qp-button>

		</div>
		<qp-fieldset id="form_01" wg-container="Filter_form" view.bind="Filter" slot="B" >
			<field name="FilterByCategory">
			</field>
		</qp-fieldset>
		<qp-fieldset id="form_01" wg-container="Filter_form" view.bind="Filter" slot="B" >
			<field name="FilterByAttributes">
			</field>
		</qp-fieldset>
	</qp-template> 
	 <qp-grid id="BulkProductSync_PXGrid1" batchUpdate="True" view.bind="BulkProductSync"></qp-grid>

	 <qp-upload-dialog
		id="UploadPackageDlg"
		key="UploadPackagePanel"
		session-key="KNCFBatchProductSyncProcess_UploadPackage"
		caption="Open Package"
		allowed-types=".xlsx">
	</qp-upload-dialog>

</template>

Thank you in advance.

Best answer by Vignesh Ponnusamy

Hi ​@rakeshe45,

Adding the solution shared in the support case, 

Implemented the upload dialogue box in the Shipment(SO302000) screen. Please try the following approach, 

Add the following in SO302000.html,


	<qp-upload-dialog id="UploadPackageDlg"
					  key="UploadPackagePanel"
					  session-key="ProjectList_UploadPackage"
					  caption="Open Package"
					  allowed-types=".zip">
	</qp-upload-dialog>


Extended SOShipmentEntry like below and to create an action, 

public class SOShipmentEntry_Extension : PXGraphExtension<PX.Objects.SO.SOShipmentEntry>
{
    public PXFilter<ProjectListUploadPanel> UploadPackagePanel;
    #region Event Handlers
    public PXAction<SOShipment> ActionImport;
    [PXButton(Category = "Import", DisplayOnMainToolbar = true)]
    [PXUIField(DisplayName = "Import")]
    protected IEnumerable actionImport(PXAdapter adapter)
    {
        return ImportPackage(adapter, null);
    }

    private IEnumerable ImportPackage(PXAdapter adapter, string projectName)
    {
        PXContext.Session.SetString("UploadProjectMode", projectName);        
        if (UploadPackagePanel.AskExt() != WebDialogResult.OK)
            return Enumerable.Empty<object>();
        FileInfo info = PXContext.SessionTyped<PXSessionStatePXData>().FileInfo["ProjectList_UploadPackage"];
        OnUploadPackage(info);
        return adapter.Get();
    }

    public bool OnUploadPackage(FileInfo info)
    {            
        if (info != null)
        {
            UploadFileMaintenance upload = PXGraph.CreateInstance<UploadFileMaintenance>();            
            try
            {
                upload.SaveFile(info, FileExistsAction.CreateVersion);
            }
            catch (PXNotSupportedFileTypeException exc)
            {
               throw new PXException("Unsupported Format");
            }
            PXNoteAttribute.SetFileNotes(Base.Document.Cache, Base.Document.Current, info.UID.Value);
        }
        return true;
    }
    #endregion
}

 

This should add the file upload dialogue box that only accepts .zip files. Please feel free to post back if you have any questions.! Good Luck,

View original
Did this topic help you find an answer to your question?

1 reply

Vignesh Ponnusamy
Acumatica Moderator
Forum|alt.badge.img+5

Hi ​@rakeshe45,

Adding the solution shared in the support case, 

Implemented the upload dialogue box in the Shipment(SO302000) screen. Please try the following approach, 

Add the following in SO302000.html,


	<qp-upload-dialog id="UploadPackageDlg"
					  key="UploadPackagePanel"
					  session-key="ProjectList_UploadPackage"
					  caption="Open Package"
					  allowed-types=".zip">
	</qp-upload-dialog>


Extended SOShipmentEntry like below and to create an action, 

public class SOShipmentEntry_Extension : PXGraphExtension<PX.Objects.SO.SOShipmentEntry>
{
    public PXFilter<ProjectListUploadPanel> UploadPackagePanel;
    #region Event Handlers
    public PXAction<SOShipment> ActionImport;
    [PXButton(Category = "Import", DisplayOnMainToolbar = true)]
    [PXUIField(DisplayName = "Import")]
    protected IEnumerable actionImport(PXAdapter adapter)
    {
        return ImportPackage(adapter, null);
    }

    private IEnumerable ImportPackage(PXAdapter adapter, string projectName)
    {
        PXContext.Session.SetString("UploadProjectMode", projectName);        
        if (UploadPackagePanel.AskExt() != WebDialogResult.OK)
            return Enumerable.Empty<object>();
        FileInfo info = PXContext.SessionTyped<PXSessionStatePXData>().FileInfo["ProjectList_UploadPackage"];
        OnUploadPackage(info);
        return adapter.Get();
    }

    public bool OnUploadPackage(FileInfo info)
    {            
        if (info != null)
        {
            UploadFileMaintenance upload = PXGraph.CreateInstance<UploadFileMaintenance>();            
            try
            {
                upload.SaveFile(info, FileExistsAction.CreateVersion);
            }
            catch (PXNotSupportedFileTypeException exc)
            {
               throw new PXException("Unsupported Format");
            }
            PXNoteAttribute.SetFileNotes(Base.Document.Cache, Base.Document.Current, info.UID.Value);
        }
        return true;
    }
    #endregion
}

 

This should add the file upload dialogue box that only accepts .zip files. Please feel free to post back if you have any questions.! Good Luck,


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings