[.NET Snippet & Macro] Checking if an item exist in Macro

In certain special scenarios, you want to only execute macro logic if a specific item exists on the form.

Macro by default does not have any "DoesItemExist" function but we can create our own using .NET code.

We want to check if the item "Foreign Name" exists on the Business Partner Master Data window.

Step 1) is to find the item uid of the item we want to check (You can use the right-click for this):

Step 2) is to create the .NET code function
This is done by opening the UF - Macro and using right-click to open .NET code:

Step 3) Write the code to check for the item and return a result (Replace 128 with your item code)

try
{
     form.Items.Item("128");
     return "true";
} catch (Exception e)
{
     return "false";
}

Step 4) Use the .NET code in the macro:

IF(@ForeignNameExist = 'true')
BEGIN
SET($[$128.0.0]|This exist);
END
ELSE
BEGIN
MessageBox(Item does not exist);
END

Step 5) Test that it works (I have used a Function Button)

Item exists:

Item does not exist:

 

Was this article helpful?

1 out of 1 found this helpful

Comments

1 comment

  • Comment author
    Ismail Orhan

    Hello,

     

    Thanks for the example. What if I need to check column if exist on the matrix? 

     

    For examle: I would like to check if ItemCode is visible on sales order line matrix.

    Morten Lilbæk Pedersen,

    Rasmus Jensen

    0

Please sign in to leave a comment.