How to insert value through X++ for edit method

I have standard edit method called RequiremntEdit() on WrkCtrResourceRequirementPart form datsource WrkCtrActivityRequirment

And the in the standard form WrkCtrResourceRequirementPart the above method added to control as data method.

My requirement is to insert value to the above field (Method) through X++, can anybody please suggest how can I do this?

You can simply call the method, can’t you?

Hi Martin, Thanks for reply,

I tried to call the method as shown in below code but did not work

[FormControlEventHandler(formControlStr(ProdParmStartUp, OkButton), FormControlEventType::Clicked)]
public static void OkButton_OnClicked(FormControl sender, FormControlEventArgs e)
{

ProdRoute prodRoute;
RecId recId;
WrkCtrId wrkCtrGrpId;
ProdId prodId ;
WrkCtrActivityRequirementType relationShipType;
WrkCtrActivityRequirement wrkCtrActivityRequirement;
ProdParmStartUp prodstrt = sender.formRun().dataSource().cursor();

while select prodRoute
where prodRoute.ProdId == prodstrt.ProdId
{
recId = prodRoute.activityRequirementSet().RecId;

WrkCtrActivityRequirement.ActivityRequirementSet = recid;

WrkCtrActivityRequirement.RelationshipType = prodstrt.RequirementType;
WrkCtrActivityRequirement.requirementEdit();

WrkCtrActivityRequirement.insert();

}
}

It is just inserting requirement type as shown below

Please suggest if any, I have to insert Requirement also and I have the value but not getting how to populate it on Requirement field

You’re calling the method, but you forgot that you wanted to set a value to it. If you call it without parameters, it simply returns the current value.

By the way, please use Insert > Insert Code to paste source code; it’ll be easier to read. Let me also clean up your code a bit:

[FormControlEventHandler(formControlStr(ProdParmStartUp, OkButton), FormControlEventType::Clicked)]
public static void OkButton_OnClicked(FormControl sender, FormControlEventArgs e)
{
	ProdRoute prodRoute;
	ProdParmStartUp prodstrt = sender.formRun().dataSource().cursor();

	while select prodRoute
		where prodRoute.ProdId == prodstrt.ProdId
	{
		RecId recId = prodRoute.activityRequirementSet().RecId;

		WrkCtrActivityRequirement wrkCtrActivityRequirement;
		wrkCtrActivityRequirement.ActivityRequirementSet = recid;
		wrkCtrActivityRequirement.RelationshipType = prodstrt.RequirementType;
		wrkCtrActivityRequirement.requirementEdit(); 

		wrkCtrActivityRequirement.insert();

	}
}

And because now it’s clear which version it is about, let me attach a version tag to this thread. Please do it by yourself next time when you’ll be creating a new thread.

Hi Martin,

Could you please help me on how to set value to it?, I am not able to get that point.

Look at the method and its documentation:

/// <summary>
    ///    Gets and sets the requirement based on name.
    /// </summary>
    /// <param name="_set">
    ///    A Boolean value that specifies whether the requirement name is set.
    /// </param>
    /// <param name="_fetchExistingRecord">
    ///    A Boolean value that specifies whether an existing subtype should be retrieved from the database.
    /// </param>
    /// <param name="_activeRecord">
    ///    A <c>Common</c> record buffer which must be a subtype to this record.
    /// </param>
    /// <param name="_wrkCtrActivityRequirementEdit">
    ///    The new capability name value when the <paramref name="set" /> parameter is true.
    /// </param>
    /// <param name="_companyId">The company ID.</param>
    /// <returns>
    ///    A string with the name of the requirement.
    /// </returns>
    public WrkCtrActivityRequirementEdit requirementEdit(
        boolean                                 _set                            = false,
        boolean                                 _fetchExistingRecord            = true,
        Common                                  _activeRecord                   = null,
        WrkCtrActivityRequirementEdit           _wrkCtrActivityRequirementEdit  = '',
        CompanyId                               _companyId = ''
        )
    {
        Common  common = _activeRecord;

        if (_fetchExistingRecord)
        {
            common = this.subtype();
        }

        if (prmisDefault(_companyId))
        {
            return common.requirementEdit(_set, _wrkCtrActivityRequirementEdit, this);
        }
        else
        {
            return common.requirementEdit(_set, _wrkCtrActivityRequirementEdit, this, false, _companyId);
        }
    }

You must use ‘true’ for the first parameter (_set). That means that you’re setting a value.

Values of other parameters depends on your business requirements. I guess you want to set _wrkCtrActivityRequirementEdit and leave _companyId empty. I don’t know what values you want to use for the other parameters.

Hi Martin, Thanks for reply

I have sent the parameters as below, still that did not work value which is prodstrt.Resource is not getting populated

 wrkCtrActivityRequirement.requirementEdit(true,true,wrkCtrActivityRequirement,prodstrt.Resource);

You can use the debugger to find out where things go wrong.