web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Supply chain | Supply Chain Management, Commerce
Answered

Add table Id to union View

(0) ShareShare
ReportReport
Posted on by 290

I have a view which is the union of the CustTrans and VendTrans. I want to know which records are for the CustTrans and which records are for VendTrans. I try to add table Id to the fields of  the view but the error comes that mapped view field cannot to be set to TableId.   I can demonstrate the records using AccountNum sequence number but I prefer not to do that because in the future, the sequence number will be changed.

So How can I show the records reference table in a union view?

PS: my current solution is  creating two separate view for custtrans and vendtrans. Then adding a computed column which returns the table name and union these two views. but I hope that there is a  more efficient way

I have the same question (0)
  • Suggested answer
    vinitgoyal2005 Profile Picture
    6,332 on at
    RE: Add table Id to union View

    Hi,

    Yes integer parameter gives the number of datasource in the Union view, This is applicable only for Union view.

    DictView dictView = new DictView(tableNum(TestView))  is not required, I had tried someting else, that line was required for that.

    you can safely remove it.

  • Nastaran Profile Picture
    290 on at
    RE: Add table Id to union View

    Thank Vinit. it works.

    The method argument is the number of data source?  and also DictView dictView = new DictView(tableNum(TestView)) is not required yes?

  • Verified answer
    vinitgoyal2005 Profile Picture
    6,332 on at
    RE: Add table Id to union View

    Hi Nastaran,

    Create 1 Union query for CustTrans and VendTrans

    Create View out of this union query.

    add a computed column to this union view with following code:

    private static server str tableName(int _branchNum)
    {
    DictView dictView = new DictView(tableNum(TestView));

    if(_branchNum == 1)
    {
    return "'CustTrans'";
    }
    else
    {
    return "'VendTrans'";
    }
    }

    pastedimage1596312417799v1.png

    Which create a SQL view as :

    SELECT T1.ACCOUNTNUM AS ACCOUNTNUM, T1.DATAAREAID AS DATAAREAID, T1.PARTITION AS PARTITION, 1010 AS RECID, (CAST(('CustTrans') AS NVARCHAR(10))) AS TABLENAME
    FROM CUSTTRANS T1
    UNION
    SELECT T1.ACCOUNTNUM AS ACCOUNTNUM, T1.DATAAREAID AS DATAAREAID, T1.PARTITION AS PARTITION, 1010 AS RECID, (CAST(('VendTrans') AS NVARCHAR(10))) AS TABLENAME
    FROM VENDTRANS T1

  • Suggested answer
    Rahul Mohta Profile Picture
    21,030 on at
    RE: Add table Id to union View

    check if voucher number could be used

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Supply chain | Supply Chain Management, Commerce

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 367

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 226 Super User 2025 Season 2

#3
Yng Lih Profile Picture

Yng Lih 149

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans