Author Topic: modify sql for view using javascript  (Read 1380 times)

ea1020

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
modify sql for view using javascript
« on: March 10, 2021, 08:50:28 am »
I am trying to modify the sql text for a view using javascript. For instance I'd like to change:
SELECT COL1, COL2 FROM [oldSchema].[table1]
to
SELECT COL1, COL2 FROM [newSchema].[table1]

I am able to do this manually using the SQL Object Properties maintenance window in the UI but can't seem to figure where this data lives in the object model.  I've tried modifying the 'viewdef' TaggedValue but without success. This temporarily modifies the text of the Notes, but doesn't change the underlying SQL:
var x = EA.Element
x = Repository.GetContextObject()
var pkg = Repository.GetPackageByID(x.PackageID)
y = x.TaggedValues.GetByName('viewdef')
var re = /oldSchema/ig
var n = y.Notes
y.Notes = n.replace(re, 'newSchema')
x.Update()
pkg.Update()

Any suggestions would be helpful.
Thanks,
Jim

qwerty

  • EA Guru
  • *****
  • Posts: 12814
  • Karma: +366/-295
  • I'm no guru at all
    • View Profile
Re: modify sql for view using javascript
« Reply #1 on: March 10, 2021, 09:29:28 am »
You modify y but you update anything but y.

q.

ea1020

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
    • View Profile
Re: modify sql for view using javascript
« Reply #2 on: March 10, 2021, 10:10:19 am »
Oy veh.  That was it. Thanks

qwerty

  • EA Guru
  • *****
  • Posts: 12814
  • Karma: +366/-295
  • I'm no guru at all
    • View Profile
Re: modify sql for view using javascript
« Reply #3 on: March 10, 2021, 06:36:53 pm »
Oy veh. Now you made me curious. What's your native language? Since it so much resembles German (Au weh) I though of Dutch, but Google did not know it. Or is that some half-English variant?

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 11849
  • Karma: +460/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: modify sql for view using javascript
« Reply #4 on: March 10, 2021, 07:30:30 pm »
It's definitely not Dutch.

I'm guessing Yiddish: https://en.wikipedia.org/wiki/Oy_vey

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 12814
  • Karma: +366/-295
  • I'm no guru at all
    • View Profile
Re: modify sql for view using javascript
« Reply #5 on: March 10, 2021, 11:36:28 pm »
:-)

q.