Auto Insert New Hires as PS Users

The following is a piece of App Engine code that will take new hires and auto insert them as a Peoplesoft User Profile with default data and component permission lists so they can use self service automatically.


  1. Local string &UserID, &UserDesc; 
  2. Local SQL &OPRDEFN_SQL; 
  3. Local string &Text; 
  4.  
  5. Declare Function CreateNewUser PeopleCode wherever.you.store.it FieldFormula; 
  6.  
  7. &OPRDEFN_SQL = GetSQL(SQL.OPR_ADD); 
  8. &cntr = 0; 
  9. While &OPRDEFN_SQL.Fetch(&UserID, &UserDesc); 
  10. CreateNewUser(&UserID, &UserDesc); 
  11. &cntr = &cntr + 1; 
  12. End-While; 
  13. /**************************************************************/ 
  14.  
  15.  
  16. Function: 
  17.  
  18. Function CreateNewUser(&UserID As string, &UserDesc As string); 
  19. &OperatorToCopy = "MODEL"; 
  20. &UserEmail = " "; 
  21. /* May need to collect personal data or whatever you'll use for a default password */ 
  22. &userpw = whatever your algorithm is for a default 
  23.  
  24. &OPRDEFN_REC = CreateRecord(Record.PSOPRDEFN); 
  25. &OPRDEFN_SQL = CreateSQL("%selectall(:1) where oprid = :2"); 
  26. &OPRDEFN_SQL.Execute(&OPRDEFN_REC, &OperatorToCopy); 
  27. If &OPRDEFN_SQL.IsOpen Then 
  28. While &OPRDEFN_SQL.Fetch(&OPRDEFN_REC); 
  29. &Session = GetSession(); 
  30. &Session.Connect(1, "EXISTING", "", "", 0); 
  31.  
  32. /* Create new User ID */ 
  33. &NewUserBC = &Session.GetCompINTFC(CompIntfc.USER_PROFILE); 
  34. &NewUserBC.InteractiveMode = False; 
  35. &NewUserBC.UserID = &UserID; 
  36. SQLExec("select oprid, emplid from psoprdefn where oprid = :1", &UserID, &oprid, &emplid); 
  37. If All(&oprid) Then 
  38. MessageBox(0, "Error", 0, 0, "User ID already exists for this emplid. Contact HRIS"); 
  39. Else 
  40. &NewUserBC.Create(); 
  41. &NewUserBC.Userdescription = &UserDesc; 
  42. &NewUserBC.EmailAddress = &UserEmail; 
  43. &NewUserBC.SymbolicID = &OPRDEFN_REC.SYMBOLICID.Value; 
  44. &NewUserBC.setpassword(&userpw, &userpw); 
  45. &NewUserBC.PrimaryPermissionList = &OPRDEFN_REC.OPRCLASS.Value; 
  46. &NewUserBC.RowSecurityPermissionList = &OPRDEFN_REC.ROWSECCLASS.Value; 
  47. &NewUserBC.ProcessProfilePermissionList = &OPRDEFN_REC.PRCSPRFLCLS.Value; 
  48. &NewUserBC.NavigatorHomePermissionList = &OPRDEFN_REC.DEFAULTNAVHP.Value; 
  49.  
  50. &OPRALIAS_REC = CreateRecord(Record.PSOPRALIAS); 
  51. &OPRALIAS_SQL = CreateSQL("%selectall(:1) where oprid = :2"); 
  52. &OPRALIAS_REC = CreateRecord(Record.PSOPRALIAS); 
  53. &NewIDType = &NewUserBC.IDTypes; 
  54. &IDTypeNum = &IDTypeNum + 1; 
  55. &NewIDRow = &NewIDType.item(&IDTypeNum); 
  56. &NewIDRow.IDType = "EMP"; 
  57. &NewAttributes = &NewIDRow.Attributes; 
  58. &AttributesNum = 1; 
  59. &NewAttrRow = &NewAttributes.item(&AttributesNum); 
  60. &NewAttrRow.AttributeValue = &UserID; 
  61.  
  62. /* We don't carry aliases forward in any fancy way so I've commented this out */ 
  63. /* &OPRALIAS_SQL = CreateSQL("%selectall(:1) where oprid = :2"); 
  64. &OPRALIAS_SQL.Execute(&OPRALIAS_REC, &OperatorToCopy); 
  65. &IDTypeNum = 0; 
  66. If &OPRALIAS_SQL.IsOpen Then 
  67. While &OPRALIAS_SQL.Fetch(&OPRALIAS_REC); 
  68. If &IDTypeNum > 0 Then 
  69. &NewIDType.insertitem(&IDTypeNum); 
  70. End-If; 
  71. &NewIDType = &NewUserBC.IDTypes; 
  72. &IDTypeNum = &IDTypeNum + 1; 
  73. &NewIDRow = &NewIDType.item(&IDTypeNum); 
  74. &NewIDRow.IDType = &OPRALIAS_REC.OPRALIASTYPE.Value; 
  75. &NewAttributes = &NewIDRow.Attributes; 
  76. &AttributesNum = 0; 
  77. If All(&OPRALIAS_REC.SETID.Value) Then 
  78. &AttributesNum = &AttributesNum + 1; 
  79. &NewAttrRow = &NewAttributes.item(&AttributesNum); 
  80. &NewAttrRow.AttributeValue = &OPRALIAS_REC.SETID.Value; 
  81. End-If; 
  82. If All(&OPRALIAS_REC.CUST_ID.Value) Then 
  83. &AttributesNum = &AttributesNum + 1; 
  84. &NewAttrRow = &NewAttributes.item(&AttributesNum); 
  85. &NewAttrRow.AttributeValue = &OPRALIAS_REC.CUST_ID.Value; 
  86. End-If; 
  87. If All(&OPRALIAS_REC.EMPLID.Value) Then 
  88. &AttributesNum = &AttributesNum + 1; 
  89. &NewAttrRow = &NewAttributes.item(&AttributesNum); 
  90. &NewAttrRow.AttributeValue = &UserID; 
  91. End-If; 
  92. If All(&OPRALIAS_REC.VENDOR_ID.Value) Then 
  93. &AttributesNum = &AttributesNum + 1; 
  94. &NewAttrRow = &NewAttributes.item(&AttributesNum); 
  95. &NewAttrRow.AttributeValue = &OPRALIAS_REC.VENDOR_ID.Value; 
  96. End-If; 
  97. If All(&OPRALIAS_REC.CONTACT_ID.Value) Then 
  98. &AttributesNum = &AttributesNum + 1; 
  99. &NewAttrRow = &NewAttributes.item(&AttributesNum); 
  100. &NewAttrRow.AttributeValue = &OPRALIAS_REC.CONTACT_ID.Value; 
  101. End-If; 
  102. End-While; 
  103. End-If; 
  104. &OPRALIAS_SQL.Close(); 
  105. */ 
  106.  
  107. /* Add all roles for user */ 
  108. &ROLEUSER_REC = CreateRecord(Record.PSROLEUSER); 
  109. &ROLEUSER_SQL = CreateSQL("%selectall(:1) where roleuser = :2"); 
  110. &ROLEUSER_SQL.Execute(&ROLEUSER_REC, &OperatorToCopy); 
  111.  
  112. &RoleNum = 0; 
  113. If &ROLEUSER_SQL.IsOpen Then 
  114. While &ROLEUSER_SQL.Fetch(&ROLEUSER_REC) 
  115. If &RoleNum > 0 Then 
  116. &NewRole.insertitem(&RoleNum); 
  117. End-If; 
  118. &RoleNum = &RoleNum + 1; 
  119. &NewRole = &NewUserBC.Roles; 
  120. &NewRoleRow = &NewRole.item(&RoleNum); 
  121. rem &NewRoleRow.Roleuser = &UserID; 
  122. &NewRoleRow.RoleName = &ROLEUSER_REC.ROLENAME.Value; 
  123. If Not &ROLEUSER_SQL.IsOpen Then 
  124. Break; 
  125. End-If; 
  126. End-While; 
  127.  
  128. End-If; 
  129. &ROLEUSER_SQL.Close(); 
  130.  
  131. /* Save new User ID */ 
  132. If Not &NewUserBC.save() Then 
  133. &MsgCollection = &Session.PSMessages; 
  134. For &I = 1 To &MsgCollection.Count 
  135. &ErrorObj = &MsgCollection.Item(&I); 
  136. &Text = &ErrorObj.Text; 
  137. MessageBox(0, "Error", 0, 0, " Could not create User " | &ErrorObj | &Text | " "); 
  138. End-For; 
  139. &MsgCollection.DeleteAll(); 
  140. End-If; 
  141. &NewUserBC.Cancel(); 
  142. End-If; 
  143. End-While; 
  144. End-If; 
  145. &OPRDEFN_SQL.Close(); 
  146. End-Function; 
  147. /**************************************************************/ 
  148.  
  149.  
  150. SQL: 
  151.  
  152. SELECT a.emplid  
  153. , a.name  
  154. FROM ps_personal_data a  
  155. WHERE EXISTS (  
  156. SELECT 'x'  
  157. FROM PS_Job B  
  158. WHERE a.emplid = b.emplid  
  159. AND b.empl_status = 'A'  
  160. AND b.effdt = (  
  161. SELECT MAX(c.effdt)  
  162. FROM ps_job c  
  163. WHERE c.emplid = b.emplid  
  164. AND c.empl_rcd = b.empl_rcd)  
  165. AND b.effseq = (  
  166. SELECT MAX(d.effseq)  
  167. FROM ps_job d  
  168. WHERE d.emplid = b.emplid  
  169. AND d.empl_rcd = b.empl_rcd  
  170. AND d.effdt = b.effdt))  
  171. AND NOT EXISTS (  
  172. SELECT 'x'  
  173. FROM psoprdefn o  
  174. WHERE o.oprid = a.emplid) 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值