Skip to Content
author's profile photo Former Member
Former Member

Test if an item in a form exist already

Hi,

How do you test if an item in a form already exist?

right now,

What I did is to put try and catch statement on a dynamic form item?

When it errors out, that's the time the item is added to the form.

Thanks,

Add a comment
10|10000 characters needed characters exceeded

Related questions

8 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 11, 2008 at 05:04 AM

    hi,

    we had the same problem and we came up with a solution which will add the item only once to a particular form Uid

    declare one class level string variable(strFormUid)

    in before action false of form_load you assign that varialbe with Form UId

    Then

    follow this

    if pval.EventType=Form_Load

    strFormUid=pVal.FormUid

    'Add the controls here

    end if

    if pval.FormUid=strFormUidthen

    write all events here(EXCEPT FORM LOAD)

    End if

    Hope it helps you

    Regards

    Vishnu

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 10, 2008 at 07:40 PM

    Hi,

    What event should you put it? I am getting error when I put it in FormActivate event. That's why I need to put try and catch. How do you prevent it from existing? The function is correct which I also demonstrated but we should limit it to be loaded only once in a form when it is loaded.

    Thanks,

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 10, 2008 at 03:21 PM

    If the item is already in then you can find it already in the Items collection of the form.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 10, 2008 at 03:48 PM

    Hi,

    I don't get you. That's why I posted it.

    try

    {

    //assign dummy variable for testing purposes

    string s = ovarForm.items.item("youritem").uniqueid;

    }

    catch(exception)

    {

    Add item in the form.

    }

    I am asking is if there's any other way to test if an item already exist and how you declare it.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 10, 2008 at 08:10 PM

    Hi David,

    I've used the same concept already before you have attempted to answer. but Is there an event where you can prevent the SAP B1 detect that it already exists in the form.

    E.g. item is added dynamically in the form and not pre-existing.

    Which event combination is best place to secure that the item is not existing?

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 10, 2008 at 08:24 PM

    That still won't work. It still getting error since it has been existing already.

    Putting it into code

    if (pVal.FormType == 134 && !pVal.Before_Action &&{

    if (EventEnum == SAPbouiCOM.BoEventTypes.et_FORM_LOAD)

    {

    if FromITemExist(Form,Item) <------ inside that function while comparing it with the item string it would already error out since the item is not unique. So far, all items are in unique Id.

    {

    logic here

    }

    }

    public static bool FormItemExist(SAPbouiCOM.Form form, string item)

    {

    bool i = false;

    if (form.Items.Item(item).UniqueID == item)

    i = true;

    return i;

    }

    Add a comment
    10|10000 characters needed characters exceeded

    • juan,

      1): better use pval.EventType

      if (pVal.FormType == 134 && pVal.BeforeAction == true && pVal.EventType == SAPbouiCOM.BoEventTypes.et_FORM_LOAD)

      {

      ...

      2): i translated/corrected the itemexists function for you to c#

      private bool ItemExists(string formUID, string itemUID)

      {

      bool ItemExists = false;

      for (int i = 0; i <= (globals.SBO_Application.Forms.Item(formUID).Items.Count - 1); i++)

      {

      if (globals.SBO_Application.Forms.Item(formUID).Items.Item(i).UniqueID == itemUID)

      {

      ItemExists = true;

      break;

      }

      }

      return ItemExists;

      }

  • author's profile photo Former Member
    Former Member
    Posted on Jan 10, 2008 at 08:58 PM

    Hi David,

    Why do you have to make a loop? while you can capture the form in ItemEvent such as

    oCurrentForm = SBO_Application.Forms.Item(FormUID);

    within that, as I emphasize below. But what needs to be captured are events that only one isntance of this item should be added. It still leaves me wandering to solve the unique Id error during loading/activate of that form.

    public static bool FormItemExist(SAPbouiCOM.Form form, string item)

    {

    bool i = false;

    if (form.Items.Item(item).UniqueID == item)

    i = true;

    return i;

    }

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 10, 2008 at 09:36 PM

    Sorry, what I meant is for items and not forms for looping.

    Anyways, I've just solved this before I posted using try catch statement i posted earlier. But I'm not comfortable using it.

    what is that globals.SBO_APPLICATION? (globals.)

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.