RSS

Get Last Selected Value on Form Control

17 May

Problem: Store last selection in the form by user

There was a requirement to store user’s last selection on the form – i.e. the site selected last time should be populated automatically when the user opens the same form again. So if the user selected siteInventory details inquiry Dynamics AX “E” the form should remember it the next time.

Solution: We can solve this problem by implementing standard Ax syslastvalue/Pack-Unpack methods. Here we store the value in variable for current user session and based on user, current extension etc. To develop this functionality add the following code on the form.

Code: Add these methods on the form and it will start working:

//class declaration

public class FormRun extends ObjectRun

{

InventSiteId                    site;

#define.CurrentVersion(1)

#localmacro.CurrentList

site

#endmacro

}

 

//pack

public container pack()

{

return [#CurrentVersion,#CurrentList];

}

 

// Unpack

public boolean unpack(container packedClass)

{

int version;

;

version = RunBase::getVersion(packedClass);

if(version)

{

[version,#CurrentList] = packedClass;

return true;

}

return false;

}

 

//Site sysLastValue: This method is use to initialize default value

Public void initParmDefault()

{

;

site = “SiteA”;

}

 

//Site sysLastValue: This method is use to store dataAreaId for current user

public dataAreaId lastValueDataAreaId()

{

return curext();

}

 

//Site sysLastValue: This method returns the name of caller

public identifiername lastValueDesignName()

{

return element.args().menuItemName();

}

 

//Site sysLastValue: This method returns the name of form/object

public identifiername lastValueElementName()

{

return this.name();

}

 

//Site sysLastValue: This method returns the type of caller

public UtilElementType lastValueType()

{

return UtilElementType::Form;

}

 

//Site sysLastValue: This method returns the name of current user

public userId lastValueUserId()

{

return curuserid();

}

 

//Site sysLastValue: on form close save site value

public void close()

{

site = StringEditSiteId.valueStr();

xSysLastValue::saveLast(this);

super();

}

 

//Site sysLastValue: on run assign value to form control

public void run()

{

super();

//get the last value stored in cache

//here unpack method used

xSysLastValue::getLast(this);

//set the last user selection on the field- this is form control for siteId

StringEditSiteId.text(site);

}

Reference : http://www.arbelatech.com/insights/blog/get-last-selected-value-on-form-control.html

Advertisements
 
Leave a comment

Posted by on May 17, 2018 in AX 2012, D365, Syslastvalue

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
Nishant Rana's Weblog

Everything related to Microsoft .NET Technology

henrikmarx

A practitioner's views on Dynamics 365 for Operations and Finance

Supreme X++

A blog about good and bad development in Microsoft Dynamics AX

Microsoft Dynamics 365

Pavan Kumar Garlapati

Microsoft Dynamics AX/365 Finance and Operations Development Blog

Technical blog about Dynamics AX 2012 and Dynamics 365 for finance and operations

Suvidha-blogpost

Dynamics 365 Blog

vmoskalenko blog

SQL, AX, Windows, Azure

Syed Rafay Ali

This blog contains information about Functional techniques and guidelines in Microsoft Dynamics AX, including tips, tricks, tutorials, tools and upcoming news enhancement in Microsoft Dynamics Ax

All About Microsoft Dynamics

Microsoft Dynamics AX, Microsoft Dynamics 365 for Finance and Operations, D365, Retail, SQL

Anitha Eswaran - Dynamics Ax

Microsoft Dynamics Ax blog

AXAPTA Hut

AxaptaHut ax = new AxaptaHut();

All About Dynamics 365

Dynamics 365, D365, Implementor

Philippsen's Blog

Everyday findings in my world of .net and related stuff

Microsoft Dynamics AX

A great WordPress.com site

Xalentis

All things Blockchain, AI and IoT

Dynamics Ax

Technical Knowledge

%d bloggers like this: