The CreatorCon Call for Content is officially open! Get started here.

How is live_profile related to sys_user?

Brian Bush
Giga Guru

Does anyone know how to find a user's live_profile sys_id using the sys_user record? It seems like there must be a relationship between these tables, but it isn't obvious. I can see a table_name field on the live_profile record that is set to sys_user. I assume there is a table somewhere that relates the sys_ids.

1 ACCEPTED SOLUTION

Uncle Rob
Kilo Patron

It won't be obvious from the User record side of the equation because the reference exists on the live_profile record.



find_real_file.png



So a couple options...


1)   Search in the live profile table for a document id that matches your user's sys_id.   That should yield 1 live profile record you can get the sys_id from


2)   Build a custom relationship that matches document id to current user id.


View solution in original post

14 REPLIES 14

Robert,



      I created the onChange after business rule below to run on insert and update, but it is not making any name changes.   Maybe I am going about this wrong because I do not know JavaScript...which may be the whole problem!




(function executeRule(current, previous /*null when async*/) {



  // Copy the name from the sys_user table to the live_profile name field


var usr = new GlideRecord("sys_user");


usr.addQuery("sys_id", current.document);


usr.query();


if (usr.next()) {


    usr.name = current.name;


    usr.update();


}


})(current, previous);


Lets rewind a bit.   Are you finding that your Live Profile names are out of synch with your User names or something?


Why are you building the script in the first place?


Yes, the live profile name is out of synch with the user name.   I was trying to make a business rule that would copy the user name to the live profile name.


Hi Robert Fedoruk,



I am currently developing a custom Service Portal and I have a requirement in which I need to get on my Service Portal widget's Server Script side, the logged-in user's sys_id in order to execute a query on the Live Message table.



This was my first approach (please see below),



var liveMessages = new GlideRecord("live_message");


liveMessages.addQuery("profile", gs.getUserID());


liveMessages.query();


data.liveMessageCount = liveMessages.getRowCount();



but unfortunatey, the code didn't retrieve the information I need.


After I saw your reply on this discussion I realized that the field "profile" on Live Message table is in fact a reference to the Live Profile table, and that is probably the reason why when I query the Live Message table passing it the user's id it didn't retrieve the count of messages of that user.



Do you have any idea on how I can query this Live Profile table in order to get user's sys_id and then use it to query the "profile" field on Live Message table?


I am missing the right syntax.




Thanks in advance.



Best regards,



Fábio Gonçalves


Integrating this into ServicePortal is beyond my experience.   However, Live_Profile records have a document reference.   In the case of users, it should be the sys_id of user record.



Does that help?