Forums

Find answers, ask questions, and connect with our
community all around the world.

Home Forum Omnis General Forum simplifying code…

  • simplifying code…

    Posted by Uwe Smidt on November 30, 2023 at 3:14 pm

    Dear $all,

    this probably is a nobrainer – but my attempts to solve it with my share of brain cells yielded no favorable results:

    Instead of the 2 lines:

    Do myList.$load(RecId) ## load record with ID...
    calculate myValue as myList.myField

    to get myValue, I would like to do this in one line like this

    calculate myValue as myList.$load(RecId).myField

    I guess it has to do with () (brackets for evaluate this first, then that…)), but I’ve done every sensible permutation of bracketing – alas, to no avail 😳.

    Maybe crowd sharing brain cells will bring the answer…

    Thanx in advance!

    Uwe

    Andreas Pfeiffer replied 3 months ago 2 Members · 3 Replies
  • 3 Replies
  • Andreas Pfeiffer

    Administrator
    December 1, 2023 at 2:07 pm

    Hello Uwe,

    I do not think that will work and this might be for two reasons. A list can have more than one line and therefore when having a list you will always need to tell which line you want the data from. But even then I do not think this will work.

    However to achieve a one liner you could encapsulate the method inside the object:

    1. make a new method in the table class, i.e. $getName

    2. this method should receive your ID and possibly the line number (if it is not a row).

    3. This could be the code:

    Do $cinst.$load(pIdent)

    Quit method $cinst.[pLine].name

    4. Then the code to call this would be like:

    Do myList.$getName(RecID,LineNo) Returns myValue

    or

    Calculate myValue as myList.$getName(RecID,LineNo)

    Does that help?

    Best,

    Andreas

  • Uwe Smidt

    Member
    December 1, 2023 at 2:48 pm

    Hi Andreas,

    yes, it does help – by knowing FOR SURE it doesn’t work – so I need not over strain my one brain cell ( I only have that one!), and by pointing me in the right direction. I will do a

    taSuper.$getValue(pSchema,pID,pFieldName)

    so I’m not limited to a predetermined field.

    Thanx a lot!

    Uwe

    • Andreas Pfeiffer

      Administrator
      December 1, 2023 at 2:51 pm

      Hi Uwe,

      great! Good idea to put it into the super class.

      Do not forget to consider the line number. If no current line is set it will be null otherwise.

      Best,

      Andreas

Log in to reply.