ServiceNow.Core 0.8.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ServiceNow.Core --version 0.8.0
NuGet\Install-Package ServiceNow.Core -Version 0.8.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ServiceNow.Core" Version="0.8.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ServiceNow.Core --version 0.8.0
#r "nuget: ServiceNow.Core, 0.8.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ServiceNow.Core as a Cake Addin
#addin nuget:?package=ServiceNow.Core&version=0.8.0

// Install ServiceNow.Core as a Cake Tool
#tool nuget:?package=ServiceNow.Core&version=0.8.0

Service Now Fluent Api

Easy to connect, and interact with Service Now Api

⚗ This library is in beta state, feel free to test and contribute

Description

Make request using fluent api!

  • 🧰 Easy to use, based on the config file it connects and authenticate without one line of code
  • 🔑 Typed data, you can use properties to manipulate and restrict requests
  • 🛠 Typed properties can be used in Selects, Queries, Ordering...
  • 🧩 Auto serialize/deserialize included
  • 🎲 Generic Json Elements available as responses
  • 📑 Methods and classes have documentation comments, get feedback as you type
  • 🗜 Compress requests by default
  • 👓 Extensions methods to change and get data from generic responses, log and much more...

Dependencies

  • .Net Core 3.1
  • .Net Framework 4.6.1

Installing

  • Install the package.
  • Set an appsettings.json with correct connection values.
    • The library check if scope has and .default or not to define how it will get access tokens
    • You can use Credentials or Client Secrets for daemon applications
  • Create an instance of ServiceNow.
  • Create an instance of a Table, (typed or not).
  • Configure the request as you like.
  • make the request with ToListAsync.

Basic Examples

  • Typed (Create any class derived from ServiceNowBaseModel class, so we have an Id Guid)
//Creating an ServiceNow instance
var ServiceNow = new ServiceNow(config);

//Creating an table instance
var usersTable = ServiceNow
    .UsingTable<User>("sys_user")
    .Limit(2)
    .WithQuery(x => $"{x.Name} like Branco and {x.Country} = BR");

//Getting data
var users = await usersTable.ToListAsync();

while (users.Count > 0)
{
    foreach (var user in users)
        Console.WriteLine(user.ToString());
    //Next Request will get the next chunk of data
    users = await usersTable.ToListAsync();
}
  • Not typed
var usersTableNotTyped = ServiceNow
    .UsingTable("sys_user")
    .Limit(2)
    .WithQuery("name like Branco and country = BR");
var usersNotTyped = await usersTableNotTyped.ToListAsync();

while (usersNotTyped.Count > 0)
{
    usersNotTyped.ForEach(userNotTyped => userNotTyped.Display());
    usersNotTyped = await usersTableNotTyped.ToListAsync();
}
  • Changing not typed Data
//Creating a table instance
var incidentsTableNotTyped = ServiceNow
    .UsingTable("incident")
    .Limit(10);

//Getting data
var incidentsNotTyped = await incidentsTableNotTyped
        .Select(new[] { "sys_id", "short_description" })
        .WithQuery("short_description like some nice")
        .OrderBy("sys_id")
        .ToListAsync();

//Updating
incidentsNotTyped.ForEach(async incident =>
{
    Guid id = new Guid(incident.GetProperty("sys_id").ToString());
    ExpandoObject inc = incident.ToObject();
    inc.UpdateProp("short_description", "changed description on non typed value");
    var changed = await incidentsTableNotTyped.Update(id, inc);
    if (changed)
        Console.WriteLine("Incident Changed");
    else
        Console.WriteLine("Incident NOT Changed");
});

You can create CatalogItem

See Exxon Service Now Docs to learn more

  • You must first create an application in studio inside ServiceNow and then:
    • Create a catalogItem
    • create a flow
var requestCatalog = serviceNow.UsingCatalog<Request>(new Guid("catalogItemIdHere"));

var request = await requestCatalog.Request(new{
    varNameHereString = "string",
    varNameHereNumber = 10,
    varNameHereReference = new Guid(sys_id),
}); ;

You can set custom Serializers (You must set it only once, this is optional)

 //AddCustom Custom Serializers to static class used in ServiceNow
JsonConverterOptions.ConfigureCustomSerializers(new[] {
    new CustomRequestStateConverter() 
});

Default Serializers for Guid and DateTime

When there is no value in the json response (while using not nullable version) it will return:

  • new DateTime() "{1/1/0001 12:00:00 AM}"
  • Guid.Empty

That happens because ServiceNow not always return null, in those cases it returns an empty string.

Help

  • You can open issues to help improve and collaborate with the library.
  • Demos included in project (only the console version for now)

Authors

Emerson Bottero Branco DBAM Automation

Version History

  • 1.0
    • Table Creation
    • Select
    • Set Headers
    • With Query
    • Limit
    • OrderBy
    • OrderByDesc
    • ToList
    • Get
    • Delete
    • Create
    • Update
    • Compression
    • Bug fix (authenticate and when token expiries)
    • Extensions methods
    • More complex console demo examples
    • Authentication Improvements
    • Working web API demo (unavailable for now)
    • Custom Serializers Settings -New JsonConverters for null-able and normal types -New Update method -When writing new Classes don't set sys_id as null -Enum.ToDescription Method -WithQuery with no arguments -ImportSet API -SnowTable Attribute in classes (remove the need to pass table name as argument in WithTable methods)
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.4 171 2/29/2024
1.1.3 199 2/5/2024
1.1.2 76 2/4/2024
1.1.1 93 1/21/2024
1.1.0 154 1/7/2024
1.0.1 1,356 7/7/2022
1.0.0 509 6/26/2022
0.8.8 520 4/10/2022
0.8.7 623 2/9/2022
0.8.6 406 2/7/2022
0.8.5 620 2/2/2022
0.8.3 223 1/13/2022
0.8.2 243 1/12/2022
0.8.1 422 1/11/2022
0.8.0 438 1/11/2022

Authentication , Exceptions, Log, Compression improvements
New JsonConverters for nullable and normal types
New Update method
When writing new Classes don't set sys_id as null
Enum.ToDescription Method
WithQuery with no arguments
ImportSet API
pagination auto-reset on WithQuery or 0 results
added logger option
add import set response