on 06-22-2016 2:42 AM
Hi all,
I need help, how to write the query to block "owner" field in document from being change other than default value ?
Thanks
Hi,
For which document you want to do this ?
Thanks,
Harshal
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I have a work around for you.
First create 1 UDF in OPOR header level and apply below FMS to get Ownercode.
SELECT $[OPOR.OwnerCode.Number]
and you can set this field as auto refresh and make it inactive so that user cannot change this UDF value.
Now apply this below SP to achieve your requirement.
IF (@object_type = '22' AND @transaction_type IN ('A', 'U')) |
BEGIN
IF EXISTS ( SELECT distinct T0.OwnerCode from OPOR T0 where T0.DocEntry = @list_of_cols_val_tab_del and T0.U_DocumentThrough <> T0.OwnerCode) | |
BEGIN | |
SELECT @error = -12, |
@error_message = 'Please do not change the owner'
END |
END
Hope this helps.
Thanks,
Harshal
Hi Harshal,
Thank you for the prompt reply.
The workaround work, but I tried to simplified by not creating the UDF. So I add the FMS to query as below, however it will block even is the right owner.
IF (@object_type = '22' AND @transaction_type IN ('A', 'U'))
BEGIN
IF EXISTS ( SELECT distinct T0.OwnerCode from OPOR T0 where T0.DocEntry = @list_of_cols_val_tab_del and (SELECT $[OPOR.OwnerCode])<> T0.OwnerCode)
BEGIN
SELECT @error = -1299,
@error_message = 'Please do not change the owner'
END
END
Hi,
How about making it equal sign.
IF (@object_type = '22' AND @transaction_type IN ('A','U'))
BEGIN
IF EXISTS ( SELECT distinct T0.OwnerCode from OPOR T0 where T0.DocEntry = @list_of_cols_val_tab_del and (SELECT $[OPOR.OwnerCode])= T0.OwnerCode)
BEGIN
SELECT @error = -1299,
@error_message = 'Please do not change the owner'
END
END
Thanks,
Harshal
Hi OLga Hu,
Please try the below SP .
IF (@object_type = '22' AND @transaction_type IN ('A','U'))
BEGIN
IF EXISTS ( SELECT distinct T1.[userId]
from OPOR T0 INNER JOIN OHEM T1 ON T0.[OwnerCode] = T1.[empID] where (T0.DocEntry = @list_of_cols_val_tab_del)
and (T0.[OwnerCode] = T1.[empID]) and (T0.[UserSign] <> T1.[userId] ))
BEGIN
SELECT @error = -1299,
@error_message = 'Please do not change the owner'
END
END
If you resolved the issue by using the above solution please mark as the correct or Helpful answer.
Rgds,
Kamlesh Naware
Hi Kamlesh,
Maybe before this my testing was not complete.
Now having problem when user try to update the document that was not created by the user.
For eg:
Invoice 16001, created by user A, owner is user A
User B tried to update the invoice 16001 and change the owner to user B, SP TN will still block it.
Can this be solve?
Thanks
Hi,
Please let me know how document owner is updated from current setup.
Below standard setup for document owner update in document.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Olga,
IF (@object_type = '22' AND @transaction_type IN ('U')) BEGIN IF EXISTS ( SELECT top 1 T1.OwnerCode FROM OPOR T0 inner join ADOC T1 on T0.DocENtry = T1.DocENtry and T1.Objtype = '22' where T1.OwnerCode <> T0.OwnerCode and T0.DocEntry = @list_of_cols_val_tab_del ORDER BY T1.LogInstanc desc) BEGIN SELECT @ERROR=1,@ERROR_MESSAGE= 'Please you cant chage the owner' END END
This query works in the Purchase Orders. I also have the same SP.
Regards,
Augusto
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Olga
Why you don't use data ownership?
Regards
Edmund
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
11 | |
10 | |
6 | |
5 | |
5 | |
5 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.