Manager field should be auto populated when we select application in service catalog - servicenow

In category maps table I have created application and application manager field. For each application I have provided manager in application manager field.. In service portal when we select application then manager field should auto populate.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading ) {
//alert("manager");
}
var user=new GlideAjax("application",doAlert);
function doAlert(user){
g_form.setValue("u_application_manager",user.u_application_manager);
}
//Type appropriate comment here, and begin script below
}`
`
I have been struck here

Related

how to modify the next link in OData query result

I have an OData Web API service using .NET 4.5. It has a WebApi controller derived from EntitySetController:
public class WorkItemsController : EntitySetController<WorkItem, string>
{
[Queryable(PageSize=100)]
public override IQueryable<WorkItem> Get()
{
// go to AWS DynamoDb, get the workitems and then return
}
}
As you can see, I set the server-side page size to 100. If there are more than 100 objects, the return will contain a link like:
<link rel="next" href="http://***/api/v1/WorkItems?$skip=100" />
This works fine with Microsoft SQL. But I am using DynamoDb. The "skip=100" can't be translated to DynamoDb LastEvaluatedKey. So here I want to modify the next link so it returns LastEvaluatedKey like this:
<link rel="next" href="http://***/api/v1/WorkItems?$skip=A12BSD123" />
So basically I want the ability to customize the link. So when user wants to get the next set, he/she just needs to use this link and I can get the LastEvaluatedKey from it.
You can set the NextLink in ODataProperties of Request after applying ODataQueryOptions like below:
public class WorkItemsController : EntitySetController<WorkItem, string>
{
public override IQueryable<WorkItem> Get(ODataQueryOptions queryOptions)
{
// go to AWS DynamoDb, get the workitems and then return
IQueryable workitems = ....;
var settings = new ODataQuerySettings { PageSize = 100 };
workitems = queryOptions.ApplyTo(workitems, settings);
// Override the NextLink here
// Get or Set Request.ODataProperties().NextLink
}
}

Editable Combobox

I have a singleton EmployeeDatabase that contains an ObservableList of employees.
This ObsList populates the contents of an editable combobox.
When a user selects one of the employees from the combo box and hits a button, I want that employee (from the database) to be displayed in a toString() in the console.
The problem is, the editable combobox does not let me select an employee directly. I'm supposed to use a StringConverter to turn that String into an Employee.
But the Employee already exists in the singleton database! Do I have to search for them in the database? Or is there an easier way to get the Employee as if the combobox weren't editable, and all I would have to do is cmbx.getSelectionModel().getSelectedItem()?
You don't need to go back to the database, since you already have an ObservableList which contains the Employees that are in there. You should be able to do something like:
final ComboBox<Employee> employeeCombo = new ComboBox<>();
employeeCombo.setItems(EmployeeDatabase.getInstance().getEmployees());
employeeCombo.setConverter(new StringConverter<Employee>() {
#Override
public Employee fromString(String string) {
for (Employee employee : employeeCombo.getItems()) {
if (string.equals(employee.getName())) { // may need more logic...
return employee ;
}
}
Employee employee = new Employee(string);
// if things are set up correctly, this call should both update the database
// and the observable list to which the combo box points
EmployeeDatabase.getInstance().add(employee);
return employee ;
}
#Override
public String toString(Employee employee) {
return employee == null : null ? employee.getName();
}
});
employeeCombo.setEditable(true);

Pass By Reference to Generic Handler(.ashx) in Asp.net

I followed this post:DataTable using Server Side Processing.
Inside default.aspx, I am calling .ashx using:
<script type="text/javascript">
$(function () {
$('#example').dataTable({
'bProcessing': true,
'bServerSide': true,
'sAjaxSource': '/data.ashx'
});
});
On Page_Load event of defaut.aspx:
Employee emp=new Employee();
emp.name="abc";
emp.addr="pqr";
emp.phone="123";
Where Employee is the name of Class.
How can I pass the Employee Object to Data.ashx?
I tried using HttpContext.Current.Session but is shows Session object as null.
Please Help.
To Access the session Inside I used IRequiresSessionState interface as below:
public class Data : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
// get Employee object from session here
Employee emp =(Employee)HttpContext.Current.Session["employee"];
}
}
Ofcourse to set an Employee object in session, on Page_Load event of defaut.aspx:
Employee emp=new Employee();
emp.name="abc";
emp.addr="pqr";
emp.phone="123";
HttpContext.Current.Session["employee"]=emp;
NOTE:
There are two interfaces present to make access available to HttpSession in Generic Handler:
IRequiresSessionState
Using this interface we can read and write the session variables.
IReadOnlySessionState
Using this interface we can only read and cannot write or edit the session variables.
For more information check this link: IRequiresSessionState vs IReadOnlySessionState

Selecting a specific value in a combobox or a table using CodedUI

I have a web aplication with a combobox and a table of elements. I need to write a method using codedUI that selects an element of the combobox or from the table, passing as parameter the "name" of the element is it possible?
If more information is needed, please ask me
thanks
You can record the action you want to test and then customize the auto-generated code inside the UIMap.Designer.cs file to select the control you need. For each control you use when you record your test the CodedUi Test Builder creates a new class inside this file. If your controls are similar (eg. control1, control2...) assign the parameter name to the Search Properties of this control:
public class UIItemWindow : WinWindow
{
public UIItemWindow()
{
#region Search Criteria
//Here assign the paramter to the search properties of the control
this.SearchProperties[WinWindow.PropertyNames.Name] = parameterName;
#endregion
}
#region Properties
public UIItemWindow1 UIItemWindow1
{
get
{
if ((this.mUIItemWindow1 == null))
{
this.mUIItemWindow1 = new UIItemWindow1(this);
}
return this.mUIItemWindow1;
}
}
#endregion
#region Fields
private UIItemWindow1 mUIItemWindow1;
#endregion
}
To see how you can pass parameters to the CodedUI test check these links:
How to: Create a Data-Driven Coded UI Test
How to read parameter values from a TestCase in Microsoft Test Manager

Creating column and then editing column givs me EntityValidationErrors

Im working on a MVC3 project using code first entity framework.
On a webpage a button is pushed.
Part of what happends is that a Sale-object is created to be saved in a database:
var newSale = new Sale
{
Id = Guid.NewGuid(),
Material = material,
Buyer = buyer,
CashOut = null,
Token = response.Token,
TimeStamp = null
};
dataContext.Add(newSale);
dataContext.SaveChanges();
After you will be redirected to another controller function that edits the value of the TimeStamp-property of the Sale object.
var dataContext = FOSDataContextFactory.Create();
var = dataContext.Sales.SingleOrDefault(x => x.Token == tokenId);
if (sale != null)
{
sale.TimeStamp = DateTime.UtcNow;
dataContext.SaveChanges();
}
When im steping through the code using the debugger everything works fine and the TimeStamp - property is changed. But when running the web-application without debugging the code a error occurs:
Validation failed for one or more entities. See
'EntityValidationErrors' property for more details.
This is the error that i got:
Entity of type:
Sale_9C4571E6D8D390FBA94D51E54B356016DF8C20533C767502369B99F24C117B5B
in state: Modified - Property: Material, Error: The Material field is
required. - Property: Buyer, Error: The Buyer field is required.
What can be the cause of this problem?
The Material and Buyer properties of your Sale entity seem to be navigation properties refering to other entities. And you likely have marked these properties as virtual which means that they get lazily loaded as soon as you access them.
If you watch these properties in the debugger you trigger lazy loading when you access them through the property watch window. This does not happen when you just run the application in Release mode. Because the properties seem to be marked as required you get the exception in Release mode because your code does not access the properties and they stay null which causes the validation exception.
You have three options to fix the problem:
Introduce foreign key properties into your model:
public class Sale
{
// ...
public int MaterialId { get; set; } // FK property
public Material Material { get; set; }
public int BuyerId { get; set; } // FK property
public Buyer Buyer { get; set; }
// ...
}
When you load the Sale entity the FK properties get loaded as well and EF will consider the required references as set and validation won't complain.
Load the navigation properties with Include:
var = dataContext.Sales
.Include(s => s.Material)
.Include(s => s.Buyer)
.SingleOrDefault(x => x.Token == tokenId);
Turn off the validation, just for this operation:
var dataContext = FOSDataContextFactory.Create();
dataContext.Configuration.ValidateOnSaveEnabled = false;
var = dataContext.Sales.SingleOrDefault(x => x.Token == tokenId);
//...
Why don't you let sql (assuming you use sql server) create the timestamp for you? You shouldn't have to set manually

Resources