# How to insert value through X++ for edit method

**URL:** <https://www.dynamicsuser.net/t/how-to-insert-value-through-x-for-edit-method/68712>\
**Category:** Developer Forum\
**Created:** [June 16, 2021, 3:23pm UTC](https://www.dynamicsuser.net/t/how-to-insert-value-through-x-for-edit-method/68712 "2021-06-16T15:23:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![malliswari](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@malliswari](https://www.dynamicsuser.net/u/malliswari)\
**Post date:** [June 16, 2021, 3:23pm UTC](https://www.dynamicsuser.net/t/how-to-insert-value-through-x-for-edit-method/68712/1 "2021-06-16T15:23:41Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [June 17, 2021, 5:20am UTC](https://www.dynamicsuser.net/t/how-to-insert-value-through-x-for-edit-method/68712/2 "2021-06-17T05:20:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![malliswari](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@malliswari](https://www.dynamicsuser.net/u/malliswari)\
**Post date:** [June 17, 2021, 2:44pm UTC](https://www.dynamicsuser.net/t/how-to-insert-value-through-x-for-edit-method/68712/3 "2021-06-17T14:44:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [June 18, 2021, 4:14am UTC](https://www.dynamicsuser.net/t/how-to-insert-value-through-x-for-edit-method/68712/4 "2021-06-18T04:14:03Z")

</div>

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:

```auto
[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.

---

<div class="post-metadata">

**Author:** ![malliswari](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@malliswari](https://www.dynamicsuser.net/u/malliswari)\
**Post date:** [June 18, 2021, 8:47am UTC](https://www.dynamicsuser.net/t/how-to-insert-value-through-x-for-edit-method/68712/5 "2021-06-18T08:47:11Z")

</div>

Hi Martin,

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

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [June 18, 2021, 9:00am UTC](https://www.dynamicsuser.net/t/how-to-insert-value-through-x-for-edit-method/68712/6 "2021-06-18T09:00:01Z")

</div>

Look at the method and its documentation:

```auto
/// <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.

---

<div class="post-metadata">

**Author:** ![malliswari](https://avatars.discourse-cdn.com/v4/letter/m/ecd19e/32.png) [@malliswari](https://www.dynamicsuser.net/u/malliswari)\
**Post date:** [June 18, 2021, 11:59am UTC](https://www.dynamicsuser.net/t/how-to-insert-value-through-x-for-edit-method/68712/7 "2021-06-18T11:59:37Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [June 18, 2021, 1:03pm UTC](https://www.dynamicsuser.net/t/how-to-insert-value-through-x-for-edit-method/68712/8 "2021-06-18T13:03:51Z")

</div>

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