Hi
André Arnaud,
Thanks for your reply,
I implemented two classes and Action Menu Item in X++.
1 CFZUnpostedJournalsByDateRange class
2 CFZUnpostedJournal class
3 CFZUnpostedJournalsByDateRange ActionMenuItem
/// <summary>
/// The CFZUnpostedJournalsByDateRange class defines a Copilot action in Dynamics 365 Finance and Operations (D365 F&O) that
/// retrieves unposted journal data within a specified date range.
/// It allows users to view unposted journals through Copilot Studio.
/// </summary>
[DataContract]
[SysCopilotChatGlobalAction]
[SysCopilotChatActionDefinition(
'MS.PA.RA.Copilot.CFZUnpostedJournalsByDateRange', // Identifier starting with "MS.PA"
'Show unposted journals by specified Date Range', // Name for the copilot action
'Present user with unposted journals for the provided date range', // Description for the Action
menuItemActionStr(CFZUnpostedJournalsByDateRange), MenuItemType::Action)] // Secured by Menu Item
public class CFZUnpostedJournalsByDateRange extends SysCopilotChatAction
{
private TransDate startDate;
private TransDate endDate;
private List unpostedJournals;
//Input parameter that is received from Copilot Studio.
[DataMember('startDate'),
SysCopilotChatActionInputParameter('Start date for the period.', true)]
public TransDate parmStartDate(TransDate _startDate = startDate)
{
startDate = _startDate;
return startDate;
}
//Input parameter that is received from Copilot Studio.
[DataMember('endDate'),
SysCopilotChatActionInputParameter('End date for the period.', true)]
public TransDate parmEndDate(TransDate _endDate = endDate)
{
endDate = _endDate;
return endDate;
}
//Output parameter, that is received by Copilot Studio once the action is executed.
[DataMember('unpostedJournals'),
SysCopilotChatActionOutputParameter('List of unposted journals')]
public List parmUnpostedJournals(List _unpostedJournals = unpostedJournals)
{
unpostedJournals = _unpostedJournals;
return unpostedJournals;
}
/// <summary>
/// This method retrieves unposted journal data from Dynamics 365 Finance and Operations within a specified
/// date range and prepares it to be used as output in a Copilot action.
/// </summary>
/// <param name = "_actionDefinition">A parameter of type SysCopilotChatActionDefinitionAttribute, representing the definition of the action to be executed by the Copilot.</param>
/// <param name = "_executionContext">An object parameter representing the context in which the action is being executed.</param>
public void executeAction(SysCopilotChatActionDefinitionAttribute _actionDefinition, Object _executionContext)
{
LedgerJournalTable ledgerJournalTable;
LedgerJournalTrans ledgerJournalTrans;
// Fetch start and end dates from parameters
TransDate fromDate = this.parmStartDate();
TransDate toDate = this.parmEndDate();
List unpostedJournalsList = new List(Types::Class);
if (fromDate && toDate)
{
// Fetch unposted journals within the specified date range
while select *
from ledgerJournalTable
group by
ledgerJournalTable.JournalNum,
ledgerJournalTable.JournalName,
ledgerJournalTable.Name,
ledgerJournalTrans.TransDate
join ledgerJournalTrans
where ledgerJournalTable.JournalNum == ledgerJournalTrans.JournalNum
&& ledgerJournalTable.Posted == NoYes::No
&& ledgerJournalTrans.TransDate >= fromDate
&& ledgerJournalTrans.TransDate <= toDate
{
// Create a new CFZUnpostedJournal object for each record
CFZUnpostedJournal unpostedJournal = new CFZUnpostedJournal();
unpostedJournal.setCFZUnpostedJournal(
ledgerJournalTable.JournalNum,
ledgerJournalTable.JournalName,
ledgerJournalTable.Name,
ledgerJournalTrans.TransDate
);
unpostedJournalsList.addEnd(unpostedJournal);
}
// Set the list of unposted journals as output parameter
this.parmUnpostedJournals(unpostedJournalsList);
}
else
{
// Handle error if dates are not provided
error('@CFZCopilotLabels:ERRProvideDateRange');
}
}
}
/// <summary>
/// Represents an unposted journal entry with details such as journal number, name, description, and transaction date.
/// </summary>
public class CFZUnpostedJournal
{
// Data members (properties)
public str JournalNum;
public str JournalName;
public str Description;
public TransDate TransDate;
public void setCFZUnpostedJournal(str _journalNum, str _journalName, str _description, TransDate _transDate)
{
JournalNum = _journalNum;
JournalName = _journalName;
Description = _description;
TransDate = _transDate;
}
}