web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to create a case using X++

(0) ShareShare
ReportReport
Posted on by

Hello experts,

I am trying to make it such that when a user presses the New button in a form, a new case will get created in MyTable and the default Case table in AX (I assume it would be "CaseDetailBase"), with a default value inserted into the table without needing the user to input any values.

I could access the detail view of a particular case I created, however, with limitations, and I have no idea how to create/ parse/ initiate a default value of a case category for it. How do we go about making it works?

A case created manually by user in All cases (can be accessed inside Common menu) via the New button has no greyed out input fields such as this screenshot here:

1884.untitled1.png

However, the case which I created/ posted via X++ has greyed-out inputs fields such as not being able to input values into Service level agreement, Case resolution, Billing project, Follow-up fields, etc. The screenshot is located below here:

4505.untitled2.png

The code which I wrote to create/posts the case is located below:

The code below is as far as I could get.

If I do lack any information at all, please let me know and I will provide it.

Thanks in advance.

private void insertRecIntoTables(boolean _newRecord = false)
{
	CaseDetailForm      caseDetailForm = new CaseDetailForm();
	CaseDetailBase      caseDetailBase; //Main table for managing case in AX	

	ttsbegin;

	if (_newRecord) //executes if the _newRecord boolean is true
	{            
		//get the next number sequence from CaseDetailForm class by using numRefCaseId's static method
		NumberSeq numberSeq = NumberSeq::newGetNum(CaseDetailForm::numRefCaseId());
		MyTable.CaseId        = numberSeq.num();
		MyTable.CaseStatus    = CaseStatus::Planned; 

		//Make a manual insert of a new record into MyTable
		MyTable.insert();
	}
	
	select forupdate caseDetailBase
			where caseDetailBase.CaseId == MyTable.CaseId;
	
	//Check to see if the record exists. If not, create one
	if (!caseDetailBase)
	{
		caseDetailBase.CaseId = MyTable.CaseId; //Pass CaseId
		
		//The fields below are hard-coded because these are considered as the default values
		if (new DictEnum(enumNum(CaseCategoryType)).symbol2Value("Services"))
		{
			//Case creation default values
			info("A value of Service exists inside CaseCategoryType enum");
			
			//I want to set the default category type as a "Service"
			//However, the code below does not work, so I commented it out...first
			//caseDetailForm.parmCategoryType(CaseCategoryType::Service); 
			
			//Hard-coded CategoryRecId as 11290924143, which is type "Service" 
			//Which is not what I want...by hard-coding it this way
			caseDetailBase.CategoryRecId = 11290924143;
			caseDetailBase.Status        = MyTable.CaseStatus;
		}
		//If "Service" string enum does not exist, force a creation of one
		else 
		{
			//I need to find out how to create an enum value in X++, which is an Int64 datatype!
		}

		caseDetailBase.insert(); //Force an insert
	}
	//else if a record exists, just update the fields in instead of creating one in CaseDetailBase
	//CaseDetailBase is an AX default system table which could be found using in AOT CaseDetail form
	else
	{
		caseDetailBase.Status = MyTable.CaseStatus; //Pass CaseStatus
		caseDetailBase.Memo   = MyTable.Memo;       //Pass memo
		caseDetailBase.update();
	 }

	ttscommit;
	
	MyTable_ds.research(true); //refresh the form's grid
}

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    I just found out the solution.

    We should be dealing with "CaseDetail" table (default AX system table), not CaseDetailBase table, as CaseDetail table extends CaseDetailBase table.

    In other words, inserting a record into CaseDetail automatically inserts the SAME record into CaseDetailBase (because its an extended CaseDetailBase).

    So, basically change this line of code

    CaseDetailBase      caseDetailBase; //Main table for managing case in AX


    to this line of code

    CaseDetail      caseDetail; //Main table for managing case in AX


    and everything works!

    Cheers!!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans