【问题标题】:Want to Map AD field account expires with the sys_user table filed which is in Date/Time format in ServiceNow. AD account expires field is in C#想要映射 AD 字段帐户在 ServiceNow 中以日期/时间格式的 sys_user 表字段过期。 AD 帐户过期字段在 C# 中
【发布时间】:2022-12-08 01:11:50
【问题描述】:

几天以来我无法解决这个问题,

我想计算用户帐户何时到期,来自 AD。

我想要一个脚本来计算用户帐户何时到期并将其映射到sys_user表字段u_acc_expire

我正在使用这个 OnBefore Transform 脚本,但仍然没有得到结果

// Updates the SN Account Expires field   
var n = source.u_accountexpires;  
var s = n.toString();  

// Only convert AD accountExpires values that begin with 1 (ex. 0 represents never expires)  
if (s.charAt(0) == 1) {  
    var dtUtil = new DateTimeUtils();
    var gDate = dtUtil.int8ToGlideDateTime(n);
    gDate.addDaysLocalTime(-1);
    target.u_account_expiration = gDate;  
}else if(!target.u_account_expiration.nil()) {  
    target.u_account_expiration = '';  
}  

【问题讨论】:

    标签: javascript active-directory datetime-format servicenow


    【解决方案1】:

    这是一个应该工作的修改后的脚本:

    // Updates the SN Account Expires field
    var n = source.u_accountexpires;
    var s = n.toString();
    
    // Only convert AD accountExpires values that begin with 1 (ex. 0 represents never expires)
    if (s.charAt(0) == 1) {
        var dtUtil = new GlideDateTimeUtils();
        var gDate = dtUtil.int8ToGlideDateTime(n);
        gDate.addDaysLocalTime(-1);
        target.u_account_expiration = gDate;
    } else if(!target.u_account_expiration.nil()) {
        target.u_account_expiration = '';
    }
    

    在原始脚本中,DateTimeUtils 类未正确实例化。这应该更改为 new GlideDateTimeUtils() 以创建该类的新实例。此外,应该使用 addDaysLocalTime 方法而不是 addDays 来正确调整本地时区。

    此脚本将根据 u_accountexpires 字段中的值,使用计算出的用户帐户到期日期更新 sys_user 表中的 u_account_expiration 字段。如果 u_accountexpires 的值不是以 1 开头,那么 u_account_expiration 字段将被清空。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-29
      • 2018-01-07
      • 2020-11-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多